先看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的正则语法进行匹配
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7719012/viewspace-1157858/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7719012/viewspace-1157858/