grep based on multiple keywords

September 28th, 2006 mysurface Posted in egrep, grep, Text Manipulation | Hits: 53815 | 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.

7 Responses to “grep based on multiple keywords”

  1. [...] 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. [...]

  2. [...] 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. [...]

  3. [...] grep based on multiple keywords grep with multiple keywords need some knowledge of regular expression. But that is not difficult, use (OR). [...]

  4. Kelly Grains Says:

    works very fine for me…
    thanks a lot…

  5. Wayne MacK Says:

    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/

  6. 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.

  7. [...] LinuxByExamples CyberCiti Like this:LikeBe the first to like this [...]

Leave a Reply