Question : Using find and grep to create a file

I have a directory containg 7 subdirectoies (mon, tue, wed, thur etc). Within each of these subdirectoies there is a set of XML file.

I wish to seach through all the files in all the directories for a given string and create a file that cotained a fully qualified path to the matching file.

The output file would contain


I was thinking i would need to do something like

find  `pwd` *.xml| grep 'searchString' *.xml > output.txt

but this doesn't work.

I have a feelling i need to use exec somewhere ....hmmm

oh and i think i am on the bash shell

thanks in advance

Answer : Using find and grep to create a file


the "find `pwd` ..." thing is actually a good idea to get the full path. But rather use "find $(pwd) ..." It's better readable!

On the other hand you could of course write the full path verbatim. This way you won't have to "cd" into the right directory beforehand.

Anyway, now for the rest -

find $(pwd) -type f -name "*.xml" -exec grep -q "searchString" {} \; -print > outputfile


Random Solutions  
programming4us programming4us