Forum Moderators: bakedjake

Message Too Old, No Replies

finding a string within a file in multiple sub/dirs

cant figure out the command - if there is one

         

PhraSEOlogy

2:19 am on Nov 2, 2004 (gmt 0)

10+ Year Member



I want to know how many occurences of the word "string" appears in multiple .html files in multiple subdirectories.

Tried things like

ls -R to get recursive list of files
cat * (the current file piped from ls)
grep "string" (then pipe to wc)

But dont seem to be able to get it to work no matter how I construct it.

I am using the bourne shell on red/hat.

wheel

3:24 am on Nov 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



grep -R string *.html

that recursively searches .html files in current directories and subdirectories. Or you could:
grep -R string *.html>filename.txt
to pump the output to a file.

PhraSEOlogy

4:21 am on Nov 2, 2004 (gmt 0)

10+ Year Member



Wheel,

I think we are going in the right direction but

grep -r string *.html

only appears to process files in "." and not the subs.

My shell wants the recurse option in lowercase.

I also tried grep --directories=recurse option but no luck.

Any ideas?

PhraSEOlogy

4:29 am on Nov 2, 2004 (gmt 0)

10+ Year Member



Wheel,

Thanks - found the problem.

grep -r string *.html .

The period at the end of the command appears to be required for the starting point directory.