Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, Any idea why following doesn't work? egrep -v 'SPAM|DNSBL|"Relay access"' mail.log ("Relay access" lines show up) Thanks...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2013
    Posts
    2

    egrep ommiting multiple strings doesn't work


    Hi,

    Any idea why following doesn't work?

    egrep -v 'SPAM|DNSBL|"Relay access"' mail.log

    ("Relay access" lines show up)

    Thanks

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,303
    Hi.

    Welcome to the forum.

    Here is an example that works for me:
    Code:
    #!/usr/bin/env bash
    
    # @(#) s2	Demonstrate inverted alternation match egrep.
    
    # Utility functions: print-as-echo, print-line-with-visual-space, debug.
    # export PATH="/usr/local/bin:/usr/bin:/bin"
    pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
    pl() { pe;pe "-----" ;pe "$*"; }
    db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
    db() { : ; }
    C=$HOME/bin/context && [ -f $C ] && $C egrep 
    
    FILE=${1-data1}
    
    pl " Input data file $FILE:"
    cat $FILE
    
    pl " Results, trying to match lines NOT containing banana, lemon, \"y z\":"
    egrep -v 'banana|lemon|"y z"' $FILE
    
    exit 0
    producing:
    Code:
    $ ./s2
    
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny, workstation) 
    bash GNU bash 3.2.39
    egrep GNU grep 2.5.3
    
    -----
     Input data file data1:
    apple
    banana
    cherry
    grape
    lemon
    orange
    y z
    "y z"
    peach
    
    -----
     Results, trying to match lines NOT containing banana, lemon, "y z":
    apple
    cherry
    grape
    orange
    y z
    peach
    I don't see many differences in the call, so there must be something else different about your versions or environment compared to mine.

    Best wishes ... cheers, drl

    PS Note the use of CODE tags for data and script.
    Last edited by drl; 10-10-2013 at 09:54 PM. Reason: Misread the question for fisrt response.
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    Just Joined!
    Join Date
    Oct 2013
    Posts
    2
    Hi drl,

    Thanks for welcoming and for your answer

    Thanks to your example now I know why it didn't work.

    I have to use

    egrep -v 'SPAM|DNSBL|Relay access' mail.log

    instead of

    egrep -v 'SPAM|DNSBL|"Relay access"' mail.log

    Thanks a lot

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    668
    Quote Originally Posted by kajax View Post
    Hi,

    Any idea why following doesn't work?

    egrep -v 'SPAM|DNSBL|"Relay access"' mail.log

    ("Relay access" lines show up)

    Thanks
    The reason is that you are telling grep the the quotes are part of the string!

    Code:
    egrep -v 'SPAM|DNSBL|Relay access' mail.log
    The '|' divides the strings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •