I want to remove all lines except the line(s) containing matching pattern.
This is how I did it:
sed -n \'s/matchingpattern/matchingpattern/p\' file.
Instead of using sed, which is complicated, use grep.
grep matching_pattern file
This should give you the desired result.