Matching Whole Word in Grep

November 7th, 2006 liewsheng Posted in grep, Text Manipulation | Hits: 59634 | 1 Comment »

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

One Response to “Matching Whole Word in Grep”

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

    wget “http://www.bannedwordlist.com/lists/swearWords.csv” -O /tmp/s ; for word in `cat /tmp/s | sed -e ’s/ /_/g’ -e ’s/,/ /g’` ; do grep -wR $word *; done | less

Leave a Reply