Hi Folks
I wanted to do something like this :
Go through all the top_level_dirs inside a particular dir.
Grep a particular string in the files in each of those dirs.
Count the occurence of that string in that file
Keep adding these (wc) values so that I can know the total occurences of that string throughout the dirs of that dir.
eg .
I have dir a. and dir b and c are subdirs to a.
Now there is a file 1.log in b/1.log and c/1.log
pwd ---> a
cat b/1.log | grep 'Hi' | wc -l --> 2
cat c/1.log | grep 'Hi' | wc -l --> 3
I want to grep "Hi" in each of them and display the total occurrences.
Please note, I am trying to do this on Command line and not in a script. Also the dir contents and the log files are astronomical so a "grep -r" is ruled out. Wanted something like,
Me@My ~]$ foreach d (`ls`)
foreach? echo $d
foreach? grep 'Hi' $d/*.log | wc -l | <Some counter that keeps adding>
foreach? end
Thanks in Advance.