grep based on multiple keywords
September 28th, 2006 mysurface Posted in egrep, grep, Text Manipulation | Hits: 65425 | 7 Comments »
grep with multiple keywords need some knowledge of regular expression. But that is not difficult, use (OR).
Let say you want to grep “me” and “you” at world.txt, you do
grep "me\|you" world.txt
You need to put ESCAPE STRING ( \ ) for OR ( | ), else it will treat it as a simbol you want to search instead of regular expression symbol.
You can do this:
grep -E "me|you" world.txt
-E treat symbol as regular expression instead.
or
egrep "me|you" world.txt
Simply use egrep for regular expression grep.







June 21st, 2007 at 12:09 am
[…] This morning, I asked to analyze log files where I need to grep the lines with two keywords, and the post grep based on multiple keywords doesn’t help much. […]
June 21st, 2007 at 7:30 am
[…] This morning, I asked to analyze log files where I need to grep the lines with two keywords, and the post grep based on multiple keywords doesn’t help much. […]
August 10th, 2007 at 1:31 am
[…] grep based on multiple keywords grep with multiple keywords need some knowledge of regular expression. But that is not difficult, use (OR). […]
March 19th, 2010 at 3:13 pm
works very fine for me…
thanks a lot…
March 16th, 2011 at 9:07 pm
Great stuff.
Helped me out greatly on a backup issue. Love the way you can just keep adding words.
eg
ls -la | egrep -v “My\ Videos|My\ Pictures|DVD”
Pumped that through my copy command and avoided some rather large directories with the following
cp -rv `ls | egrep -v “My\ Videos|DVD”` /backup/MyDocuments/
October 20th, 2011 at 3:15 am
Could you please help me regarding while connect putty Linux based logs like collect grep is working
tail -f test_log | grep ‘\” 50[0234]’ – working
tail -f test_log | grep ‘\” 50[0234]’ | grep “404” – not working
Any one help me on this regard? how to collect 1.500 to 504 2.404 alone.
October 20th, 2011 at 3:50 pm
[…] LinuxByExamples CyberCiti Like this:LikeBe the first to like this […]