grep with regex functionality in linux
$ echo 'HI' | grep '\w*'
HI
$ echo 'HI' | grep '\w+'
$ echo 'HI' | grep '\w{2}'
For cases 2 & 3, grep must have returned 'HI', but is returning nothing. 开发者_高级运维Is there something wrong in what I am grepping for?
Regular expressions in their pure form is precisely what Global Regular Expression Print supports. The \w
escape was introduced in Perl regular expressions in the late 1980s, almost 20 years after grep was created. The GNU grep suite alludes to a command pgrep
in its documentation, but you are probably better off learning the differences, and learning to use traditional regexes with grep.
精彩评论