grep命令的-o和-P选项

先看man中介绍:      
-o, --only-matching:
              Show only the part of a matching line that matches PATTERN.
-P, --perl-regexp:
              Interpret PATTERN as a Perl regular expression.

 

例如

#   echo "helloworld123456"| grep -o -P '/d+'

 

返回  123456

#echo "helloworld123456"| grep -o -P '[a-z]+'

返回  helloworld

 

-P 选项是利用PERL的正则语法进行匹配

你可能感兴趣的:(shell,script,perl)