Skip to content

Latest commit

 

History

History
29 lines (18 loc) · 738 Bytes

201109081021.txt.md

File metadata and controls

29 lines (18 loc) · 738 Bytes

20.22 Debian自带的grep不支持-P

http://scz.617.cn/unix/201109081021.txt

Q:

在Debian上执行"grep --help"可以看到:

-P, --perl-regexp PATTERN is a Perl regular expression

但实际测试表明Debian自带的grep不支持-P:

$ echo 'foobar_infix_bar' | grep -P '(?<!foo)bar' grep: Support for the -P option is not compiled into this --disable-perl-regexp binary

A: scz@nsfocus 2011-09-08 10:21

Debian有变通解决方案,用pcregrep即可。

aptitude install pcregrep

据说aptitude比apt-get更好。

$ echo 'foobar_infix_bar' | pcregrep '(?<!foo)bar' foobar_infix_bar $ echo 'prefix_foobar_suffix' | pcregrep '(?<!foo)bar' $ echo 'foobar' | pcregrep 'foo(?!bar)' $ echo 'foo_bar' | pcregrep 'foo(?!bar)' foo_bar