Remove occurrences of string in text file Remove occurrences of string in text file linux linux

Remove occurrences of string in text file


sed -i -e 's/goodbye//g' filename

To delete multiple words:

sed -i -e 's/\(goodbye\|hello\|test\|download\)//g' filename


If you are looking for Linux file through Vi mode. Please find below solution which helped me out

:g/goodbye/d - This will delete all goodbye's

:%g!/goodbye/d - This will delete all except goodbye's

Even if you're using a Windows machine, you can download and configure the Ubuntu shell and use the above commands.