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.
This might work for you:
sed -n '/matchingpattern/p' file.txt
/.../ is an address which may have actions attached in this case p.
/.../
p