ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用perl代替grep

用perl代替grep

原创 Linux操作系统 作者:lawzjf 时间:2007-03-20 00:00:00 0 删除 编辑

[root@redhat ~]# cat law
Hi, David,
I think I failed my anatomy test yeserday. I had a terrible
stomachache. I think I ategreen tom too many fried green tomatoes.
Anyway, Tom, I need your help. I'd like to make the test up
tomorrow, green tom,but don't know where to begin My studying. Do you
think you could help me? After work, about 7 PM,come to
my place and I'll treat you to pizza in return for your help. Thanks.

grep效果:

[root@redhat ~]# grep 'Tom' law
Anyway, Tom, I need your help. I'd like to make the test up

[root@redhat ~]# perl -wnl -e '/Tom/ and print;' law
Anyway, Tom, I need your help. I'd like to make the test up

grep -v 效果:

[root@redhat ~]# perl -wnl -e '/tomorrow/ or print;' law

Hi, David,
I think I failed my anatomy test yeserday. I had a terrible
stomachache. I think I ategreen tom too many fried green tomatoes.
Anyway, Tom, I need your help. I'd like to make the test up
think you could help me? After work, about 7 PM,come to
my place and I'll treat you to pizza in return for your help. Thanks.

[root@redhat ~]# grep -v 'tomorrow' law
Hi, David,
I think I failed my anatomy test yeserday. I had a terrible
stomachache. I think I ategreen tom too many fried green tomatoes.
Anyway, Tom, I need your help. I'd like to make the test up
think you could help me? After work, about 7 PM,come to
my place and I'll treat you to pizza in return for your help. Thanks.

grep -l 效果:

[root@redhat ~]# perl -wnl -e '/Tom/ and print $ARGV and close ARGV;' law greplaw

law
[root@redhat ~]# grep -l 'Tom' law greplaw
law

grep -i 效果::

perl -wnl -e '/RE/i and print;' file file2 ...


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/37724/viewspace-152579/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-18

  • 博文量
    279
  • 访问量
    990821