-1

I've been pulling my hair on this slightly.

I'm trying to use the find command to achieve the following;

find ./folder -name "folder names x" -exec grep -H "String, Text, Here" {} \; -print

folder names x- appear in multiple locations at different levels.
String, Text, Here - is the text string I want to search for given files within the above folder names only.

I could return a list of folder names then create a specific grep within those, but I want to try and streamline this into one command if possible.

Although I've used Unix for a number of years, I still haven't done scripting, but happy to try if I need to.

Thanks for any help.

Andrew

Jotne
  • 40,548
  • 12
  • 51
  • 55
Andrew
  • 1

1 Answers1

0

OK sorted it finally. Love unix but god it doesn't forgive if you don't know its language!

find ./ -name foldername -type f -exec grep -H "string, text, here" {} \; >outputfile.txt &

foldername - just that, whatever the foldername is that you want. Note, this site looses the ** around the foldername, so put one either side of the foldername for wildcard searching.

"string, text, here" - with commas if that's what you need, or just "text" if it's more basic.

outputfile.txt - whatever the output file is or just use -print for display onscreen.

& - to run in the background if it's a long search like mine.

Andrew
  • 1