The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: Recursive grep
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #8 (permalink)  
Old 05-17-2008
upstate_boy upstate_boy is offline
Registered User
 

Join Date: May 2008
Posts: 8
Jim, thanks for spelling it out for me. I got it to work but it's not producing the results I need. The results going to the results.txt are the actual contents of the files, and they are not matching my string fully. I need the files that contain the strings I'm searching - which I realize I didn't state clearly initially.

The 2 scripts I've come up with are:

for h in `cat strings.txt`; do echo "**$h**" ; grep -rl $h /path/to/search/ >> results.txt ; done

and

for h in `cat strings.txt`; do find /path/to/search/ -name \*xml -exec grep -l "$h" {} \; >> results.txt ; done


The grep and the find are working fine, it's the `cat` that is giving me trouble. The strings in strings.txt are getting broken up into smaller strings - which I verified by putting that echo in on the grep script.

Example of string in strings.txt is:

/sample/string in/strings file/title.jsp

The cat (and grep -f) is breaking it up into:

/sample/string
in/strings
file/title.jsp

I've tried putting the string in strings.txt in both single and double quotes:

"/sample/string in/strings file/title.jsp"
'/sample/string in/strings file/title.jsp'

and have also tried putting single and double quotes in the scripts:

for h in "`cat strings.txt`"; do echo "**$h**" ; grep -rl "$h" /path/to/search/ >> results.txt ; done

And the echo still shows the string being split into 3 smaller strings.




Thanks upstate boy

Last edited by upstate_boy; 05-17-2008 at 07:16 AM.
Reply With Quote