grep 2 items in a file
Hi all.
I have collection my routers configuration through rancid. Now i want to do the following, Display all the files that contain the following words C1841 AND HWIC-4ESW I want to display all the files that contains both these words. Is it possible using grep ? |
Hi,
Would this helps: grep "C1841" * | grep -m1 "HWIC-4ESW" The -m1 is there to stop searching if one match is found (this will prevent the printing of the same filename if the match occurs more then once). Hope this helps. |
Dear Sir,
the output of grep 'C1841' * doesnt give any line that contains HWIC-4ESW also. So its not working. I read about agrep, i have installed it, but its and (;) operator is not working ! Kindly guide me pls |
Hi,
Quote:
grep -lm1 "HWIC-4ESW" $(grep -lm1 "C1841" *) Hope this helps. |
Maybe awk may be able to help too:
Code:
awk 'FNR==1{x=0}/C1841|HWIC-4ESW/{x++}x==2{print FILENAME;nextfile}' * |
Hi,
Quote:
|
Quote:
egrep 'C1841|HWIC-4ESW' filename |
@geovg: That will find C1841 or HWIC-4ESW, not C1841 and HWIC-4ESW :)
|
Well I will go back to my original line :)
Code:
awk 'FNR==1{x=0}/C1841/{x++}/HWIC-4ESW/{x++}x==2{print FILENAME;nextfile}' * |
Quote:
I might even like this one better then mine: Just one command, although probably a bit more complicated for the novice. |
I will check the awk command and will let you guys know about it. But what about agrep ? i have read that following can do
agrep 'C1841;HWIC-4ESW' filename But i have been trying that with no success. Has anyone tried it ? |
And really thank you for answering. I really owe you guys a lot
|
agrep ... never heard of it before, but just googled it and there it was :doh: have no idea how to use it though :(
|
Hi,
I also never heard of agrep before you brought it up, so cannot help you with that one.... Quote:
|
Code:
agrep 'C1841;HWIC-4ESW' filename Code:
awk 'FNR==1{x=0}/C1841/{x++}/HWIC-4ESW/{x++}x==2{print FILENAME;nextfile}' * Code:
awk 'FNR==1{C=H=0}/C1841/{C=1}/HWIC-4ESW/{H=1}C&&H{print FILENAME;nextfile}' * |
All times are GMT -5. The time now is 08:23 PM. |