Linux – remove text from file


I want to remove some text from file1.txt.

I put the text in the file tmp and do:

grep -f tmp file.txt

But it gives me only the difference.

The question is how to remove the difference from file.txt.

Best Answer

Doing grep -f tmp file.txt will display all lines containing the work text (assume tmp just contins the work text). If want to display all the lines that don't contain the word text you need to use the -v option to invert the match:

$ grep -v 'text' file.txt

If you print all the lines in the file but just remove all occurrences of text then:

$ sed 's/text//g' 
Related Question