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?

Upvotes: 0

Views: 1504

Answers (1)

tripleee
tripleee

Reputation: 189427

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.

Upvotes: 3

Related Questions