Return only pattern matched string from grep

2

Is it possible to search and print only the matched pattern from grep. The default action is to print the whole line.

usercccd

Posted 2011-04-25T02:31:02.003

Reputation: 203

Answers

3

Yes. Use the -o option, e.g.,

$ echo 'hello wide world' | grep -o wide
wide

garyjohn

Posted 2011-04-25T02:31:02.003

Reputation: 29 085