Sed – how to remove all lines that do not match

sedtext processing

I have a html file. I want to remove all lines that do not start with <tr>.

I tried:

cat my_file | sed $'
s/^[^tr].*//
' | sed '/^$/d'

but it deleted all the lines.

Best Answer

Try this with GNU sed:

sed -n '/^<tr>/p' file

or

sed '/^<tr>/!d' file
Related Question