|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Grep multiple lines from a text file
I have a list of words that I want to grep in many files to see which ones have it and which ones dont.
in the text file I have all the words listed line by line, ex: list.txt: check try this word1 word2 open space list .. I want to grep each line one by one. like I want it to grep "check" *.log grep "try this" *.log grep "word1" *.log .. etc how can I do this? and maybe write the output to a file. Thanks |
|
#2
|
||||
|
||||
|
One pssibility would be to write a shell script looping through an array of words
|
|
#3
|
|||
|
|||
|
Quote:
A simple script like this should do it: Code:
cat $1 | while read search do grep "$search" *.log >> output.file done Note that you'll need to clear the output file if you re-run this. There's a lot more you can do with this, but it's a stub to get you started. |
|
#4
|
|||
|
|||
|
I'd suggest using the -l (ell) option to just list the filename in which the match occurs.
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop |
|
#5
|
||||
|
||||
|
Or maybe even just read the manual
Quote:
As in grep --file=list.txt *.log
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. |
|
#6
|
|||
|
|||
|
Quote:
RTFM: man [ef]grep (mybe also: man exec) ![]()
__________________
working on Solaris[5-9], preferred languages french and C. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > Linux Help > Grep multiple lines from a text file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|