0

How would I use sed to delete all lines in a text file which do not contain a specific string?

sed '/pattern to match/d' ./infile

I used this command, but it deletes the lines MATCHING a specific pattern, but what I want is to delete the lines which DO NOT contain a specific pttern?

2
  • Try sed '/pattern_to_match/!d' file Commented Feb 3, 2023 at 6:48
  • thank yu so much, it worked for me. Commented Feb 3, 2023 at 7:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.