It would be more helpful if you provided an actual example of the text, to help avoid any trouble spots in our answers. It's hard to give specific advice when we have to guess the requirements.
In any case, I'd now recommend using
ed instead of
sed for simple modifications like this, as it's an actual text editor, and should be fully portable across platforms.
Code:
printf '%s\n' 'v/pattern/d' ',p' 'w' | ed -s file.txt
First, I used
printf pipe the commands into
ed, separated by newlines.
'
v' runs the command on all lines that
don't contain '
/pattern/', and '
d' deletes them.
The '
,p' command prints it to the screen (for confirmation), and the '
w' command writes the changes back to the file (only use it when you're ready to commit).
How to use ed:
http://wiki.bash-hackers.org/howto/edit-ed
http://snap.nlc.dcccd.edu/learn/nlc/ed.html
(also read the info page)
It's also possible to use vi/vim in a similar way.