Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to filter lines like the following:

[javac] /Users/looris/Sviluppo/android/projects/toutry/src/net/looris/toutry/Stuff.java:23: warning: unmappable character for encoding ascii
[javac]             return (poked=false); // NOTA: è un'assegnazione, non un controllo!
[javac]                                                ^

I've tried |grep -v -A2 "unmappable character for encoding ascii" but it just does nothing.

If I just do |grep -v "unmappable character for encoding ascii" it does filter that line, but I need to filter the following two lines too.

(using "grep (GNU grep) 2.5.1" under OSX 10.5)

share|improve this question
    
I don't think you can mix -v and -A but You should be able to use sed or awk instead. – Nifle Apr 17 '10 at 15:52
up vote 2 down vote accepted

If you call grep -A2 -v, it will start to skip lines if there are more then 2 lines righ after each other that contains the search pattern, which is obviously not what you want. Try this:

| awk 'BEGIN { skip = 0 } /unmappable character for encoding ascii/ { skip = 3 } { if (skip > 0) { skip-- } else { print $0 } }'

The AWK code expanded:

BEGIN { 
    skip = 0
}
/unmappable character for encoding ascii/ { 
    skip = 3
}
{ 
    if (skip > 0) { 
        skip--
    } else { 
        print $0
    } 
}
share|improve this answer
    
awesome, thanks! – o0'. Apr 17 '10 at 20:04
    
unfortunatly this method has the problem of killing the return value. Any solution? – o0'. Apr 18 '10 at 15:06
    
well, a workaround: if ($COMPILE) { $CE=xsys('ant debug>/tmp/antdebug.out'); xsys('cat /tmp/antdebug.out| awk \'BEGIN { skip = 0 } /unmappable character for encoding ascii/ { skip = 3 } { if (skip > 0) { skip-- } else { print $0 } }\''); $CE and diex("Compile error"); } – o0'. Apr 18 '10 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .