[plug] grep and locate

Matt Kemner zombie at penguincare.com.au
Fri Nov 5 14:45:18 WST 2004


On Fri, 5 Nov 2004, quoth Mat Menzel:

> I've a question about grep and locate. How would I write a command to, say
> look in every file with 'foo' in the title for the word 'bar'

Something like:

for FILE in `locate foo`
do
  grep -H bar "$FILE"
done

Although you are better off using "find -print0" such as:

find . -name "*foo*" -print0| xargs -0 grep -H bar

which will guard against special[0] characters in the filenames.

 - Matt(wondering if he just completed someone's uni assignment ;)

[0] special to the shell, such as spaces, brackets etc.




More information about the plug mailing list