How can I do a pattern OR pattern grep?

Help
ToneSurfer
2005-01-27
2013-04-24
  • ToneSurfer

    ToneSurfer - 2005-01-27

    When I try to do grep search looking for pattern 1 OR pattern 2 it doesn't work. Ex:

    grep -e a|b file.txt

    Should find lines that have either a or b in them.

    Doesn't work. NT cmd pukes on the | character. So I try to escape it with ^| as in:

    grep -e a^|b file.txt

    Still doesn't work.

    I can do multi -e patterns as in:

    grep -e a -e b file.txt

    Shouldn't the | symbol work however?

     
    • Eric Pement

      Eric Pement - 2005-03-17

      > grep -e a^|b file.txt
      >
      > Still doesn't work.

      Use the double quotes around expressions that contain the pipe (|) or the redirection arrows (>, <), and also prefix the pipe with a backslash. This will work on Windows NT/2K/XP:

         grep "a\|b" file.txt

         egrep "a|b" file.txt

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks