Search code examples
linuxwindowstextcommand-line

Remove occurrences of string in text file


How would you remove a specific string from a text file (command line) e.g.

hello
goodbye
goodbye
hello
hello
hello
goodbye

In this case I would like to remove all occurrences of "goodbye"

Either linux or Windows, (as longs as the linux command is available in GNU)


Solution

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

    To delete multiple words:

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