Text Processing – How to Remove Lines Containing Specific Text in a File

sedtext processing

I have a file with a list of emails in it and each line has an email in it. I want to remove lines that contain the string example.com or test.com.

I tried this:

sed -i 's/example\.com//ig' file.txt 

But it will remove only the string example.com, how can I remove the entire line?

Best Answer

With GNU sed:

sed '/example\.com/d;/test\.com/d' -i file.txt

will remove the lines with example.com and test.com.

From man sed:

d      Delete pattern space.  Start next cycle.
Related Question