Have sed ignore non-matching lines

Use Perl:

... |& perl -ne 'print "$1\n" if /^\[wrote (.*\.class)\]$/'

If you don't want to print lines that don't match, you can use the combination of

  • -n option which tells sed not to print
  • p flag which tells sed to print what is matched

This gives:

sed -n 's/.../.../p'

Another way with plain sed:

sed -e 's/.../.../;t;d'

s/// is a substituion, t without any label conditionally skips all following commands, d deletes line.

No need for perl or grep.

(edited after Nicholas Riley's suggestion)

Tags:

Sed