Delete all lines except the ones containing the word 'word' in the file 'filename'

sed '/word/!d' filename.txt

Delete all lines except the ones containing the word 'word' or the word 'word2' in the file filename

sed '/word\|word2/!d' filename.txt