How to grep for the whole word

josh picture josh · May 21, 2010 · Viewed 94.6k times · Source

I am using the following command to grep stuff in subdirs

find . | xargs grep -s 's:text'

However, this also finds stuff like <s:textfield name="sdfsf"...../>

What can I do to avoid that so it just finds stuff like <s:text name="sdfsdf"/>

OR for that matter....also finds <s:text somethingElse="lkjkj" name="lkkj"

basically s:text and name should be on same line....

Answer

Derek H picture Derek H · May 21, 2010

You want the -w option to specify that it's the end of a word.

find . | xargs grep -sw 's:text'