2 Replies Latest reply: Jun 3, 2013 6:55 AM by 446 RSS

    Usage of egrep and grep!!!

    446
      Hi -
      I would like to know when we need to use egrep, grep and egrep -wvi in a shell script.Also can you tell me usage of following command-

      egrep -vi POC\|commerce\|dml-file |grep -i "2000\.

      Regards
      446

      Edited by: 446 on Jun 3, 2013 3:58 AM
        • 1. Re: Usage of egrep and grep!!!
          Catch~22
          Direct invocation of egrep and fgrep is deprecated, but provided to allow historical applications that rely on them to run unmodified. Instead use grep -E and grep -F for the same purpose.

          To find out what -wvi does, I suggest to check the man page (man grep). The -v options is used to invert the sense of matching, meaning the grep command will output those lines that do NOT match the search pattern.

          The "\" in your example is used to escape the "|", so that the shell does not interpret the character as a pipe command, but use it as a delimiter to separate search patterns.

          For instance:

          $ cat sample
          this is POC
          the brown cat
          all commerce
          jumps over the lazy dog
          in one dml-file
          until the year 2000
          $ egrep -v POC\|commerce sample
          the brown cat
          jumps over the lazy dog
          in one dml-file
          until the year 2000
          The following uses grep to do the same:

          $ grep -v -E "POC|commerce" sample
          the brown cat
          jumps over the lazy dog
          in one dml-file
          until the year 2000
          • 2. Re: Usage of egrep and grep!!!
            446
            Excellent stuff..Thanks for your quick repsonse Dude!!!