Matching Whole Word in Grep

November 7th, 2006 liewsheng Posted in grep, Text Manipulation | Hits: 68369 | 2 Comments »

Is “grep” capable to match a whole word? The answer of cause is yes!!

grep -w "keyword" filename

this will only display the line with matching word. Using the file contents in previous example, if this command enter:

grep -w "ates" filename 

you will get:

ates, 953645

2 Responses to “Matching Whole Word in Grep”

  1. A one-line bash script to find swear words in sourcecode before releasing it to clients:

    wget “” -O /tmp/s ; for word in `cat /tmp/s | sed -e ’s/ /_/g’ -e ’s/,/ /g’` ; do grep -wR $word *; done | less

  2. This can not be right… grep -v “word” means: filter out the lines with that word. Maybe you meant grep -w?

Leave a Reply