How to do "grep" on each file in directory
Hello,
Can someone show me how I can do the following in a bash script? 1) Load all *.log files into an array variable 2) Iterate through the array, and do a "grep" on each of the file to see if it contains a "word". |
Quote:
grep PATTERN *.log ? |
I am with Sergei, I feel you are over thinking your solution.
|
C'mon guys, bash now supports associative arrays - wouldn't be too difficult to do ....:p
|
This sounds like a homework question. If you want further help, you should post what you have tried. Look in the bashref manual and read through section 6.7 for information about using array variables.
|
No this is not a homework question. Unfortunately I can't recall the reason why I was thinking of doing it this way. I have moved on to other projects, and will need to re-visit this at another time. Will post here what I've tried previously.
However, I think it's because of the reason I want to see what it had grepped on what file. So I think I've echoed the file name first, with `grep <word> $filename[count]` ...... Can't remember the exact syntax. But the grep result overwrites part of the echoed file name. |
Quote:
|
And consider 'find' with '-exec'.
|
grep -r "word" /directory
- or - for i in `ls /directory`; do grep "word" $i; done |
All times are GMT -5. The time now is 07:30 AM. |