grep command

I want to use the grep command to find only the word "who" and nothing else. For instance I don't want to find "whoever"

I used this command:

grep 'who' file1

this obviously doesn't work.


Any suggestions?
Last edited on
Well if you want to find who word, you can use this.

grep ' who ' file1

Space, appended both sides.
Typically, I prefer Perl Regex for this. For example:
grep -PHn '\bwho\b' file1

The -P option enables Perl Regex, the -H option prints the filename of any match, and the -n option prints the line number of the match. In Perl Regex, \b matches a word boundry.

For more information:
man grep
man perlre
Last edited on
just use following syntax:
grep -w 'who' file1

-w option will search for whole word
Topic archived. No new replies allowed.