1

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)

1
  • I don't think you can mix -v and -A but You should be able to use sed or awk instead.
    – Nifle
    Apr 17, 2010 at 15:52

1 Answer 1

2

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
    } 
}
2
  • unfortunatly this method has the problem of killing the return value. Any solution?
    – o0'.
    Apr 18, 2010 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, 2010 at 15:11

You must log in to answer this question.

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