how to filter a phrase (ends in newline) from terminal output

59 views Asked by At

So I'm running my specs and there's an annoying error message that interpolates itself into the output. I don't want to fix the problem that's causing the error message. I just think it would be nice to filter it out using sed or awk or something.

Let's say the error message is this:

I'm an annoying error message that ends in a newline.

And so my experience is something like this:

$ rspec
....f....*.....I'm an annoying error message that ends in a newline.
............................................................I'm an annoying error message that ends in a newline.
....................................................

Whereas the ideal experience would be:

$ rspec | sed something
....f....*....................................................................................................

I've gotten pretty far by doing this:

$ rspec | sed 's/I'"'"'m an annoying error message that ends in a newline.//'

but it leaves a newline everywhere the message would have been. And for some reason tacking on \n makes it stop matching.

Thanks for reading!

1

There are 1 answers

0
Zombo On
awk 1 RS='zulu\n' ORS=

Input

alpha bravo charlie
delta echo zulu
foxtrot golf hotel
india juliet zulu
kilo lima mike

Output

alpha bravo charlie
delta echo foxtrot golf hotel
india juliet kilo lima mike