I am surprised that I cannot find a question similar to this one on SO.
How to use sed to delete all lines that do not contain a specific pattern.
For example, I have this file:
cat kitty dog giraffe panda lion tiger
I need a sed command that, when called, will delete all lines that do not contain the word cat :
cat kitty dog
source share