免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123
最近访问板块 发新帖
楼主: aku1

一个抽取的问题 [复制链接]

论坛徽章:
13
双鱼座
日期:2013-10-23 09:30:05数据库技术版块每日发帖之星
日期:2016-04-20 06:20:00程序设计版块每日发帖之星
日期:2016-03-09 06:20:002015亚冠之塔什干火车头
日期:2015-11-02 10:07:452015亚冠之德黑兰石油
日期:2015-08-30 10:07:07数据库技术版块每日发帖之星
日期:2015-08-28 06:20:00数据库技术版块每日发帖之星
日期:2015-08-05 06:20:002015年迎新春徽章
日期:2015-03-04 09:57:09辰龙
日期:2014-12-03 14:45:52酉鸡
日期:2014-07-23 09:46:23亥猪
日期:2014-03-13 08:46:22金牛座
日期:2014-02-11 09:36:21
发表于 2015-07-23 11:17 |显示全部楼层
本帖最后由 bikong0411 于 2015-07-23 11:18 编辑

回复 20# MMMIX
  1. cat 1.pl
  2. $str='02/07/2015  *    L    2014:0306.1  [RHSA-2014:0159-01] Important: kernel
  3. security and bug fix update';

  4. print split(/[][]/, $str)[1];
  5. $perl 1.pl
  6. syntax error at 1.pl line 4, near ")["
  7. Execution of 1.pl aborted due to compilation errors.
  8. $ perl -v

  9. This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
  10. (with 2 registered patches, see perl -V for more detail)

  11. Copyright 1987-2013, Larry Wall

  12. Perl may be copied only under the terms of either the Artistic License or the
  13. GNU General Public License, which may be found in the Perl 5 source kit.

  14. Complete documentation for Perl, including FAQ lists, should be found on
  15. this system using "man perl" or "perldoc perl".  If you have access to the
  16. Internet, point your browser at http://www.perl.org/, the Perl Home Page.
复制代码

论坛徽章:
0
发表于 2015-07-23 15:46 |显示全部楼层
[oss@localhost log]$ cat line.log
02/07/2015  *    L    2014:0306.1  [RHSA-2014:0159-01] Important: kernel security and bug fix update
10/12/2015       L    2014:2962.1  [RHSA-2014:1655-01] Moderate: libxml2 security update
[oss@localhost log]$ perl -e '{@t=`cat line.log`;grep{if($_=~/(^\d.*?\d{4}).*?(\[.*\]).*/){print "$1\t$2\n";};}@t}'
02/07/2015      [RHSA-2014:0159-01]
10/12/2015      [RHSA-2014:1655-01]

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
发表于 2016-09-11 20:31 |显示全部楼层

你写的代码有问题, 肯定会报错啊!

论坛徽章:
307
程序设计版块每周发帖之星
日期:2016-04-08 00:41:33操作系统版块每日发帖之星
日期:2015-09-02 06:20:00每日论坛发贴之星
日期:2015-09-02 06:20:00程序设计版块每日发帖之星
日期:2015-09-04 06:20:00每日论坛发贴之星
日期:2015-09-04 06:20:00每周论坛发贴之星
日期:2015-09-06 22:22:00程序设计版块每日发帖之星
日期:2015-09-09 06:20:00程序设计版块每日发帖之星
日期:2015-09-19 06:20:00程序设计版块每日发帖之星
日期:2015-09-20 06:20:00每日论坛发贴之星
日期:2015-09-20 06:20:00程序设计版块每日发帖之星
日期:2015-09-22 06:20:00程序设计版块每日发帖之星
日期:2015-09-24 06:20:00
发表于 2016-09-11 20:38 |显示全部楼层
  1. perl -ple '($_)=/\[([^]]+)/' f
复制代码

论坛徽章:
0
发表于 2016-09-16 20:38 |显示全部楼层
  1. #!/usr/bin/perl

  2. use warnings;
  3. use strict;

  4. while (<>) {
  5.         chomp;
  6.         if (/(\d+\/\d+\/\d+).*?(\[\S+\])/) {
  7.                 print $1, "\t", $2, "\n";
  8.         }
  9. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP