Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nepsilon/0be4c8250bab42e2f40b7b860f9064ab to your computer and use it in GitHub Desktop.
Save nepsilon/0be4c8250bab42e2f40b7b860f9064ab to your computer and use it in GitHub Desktop.
How to delete lines containing a given string? — First published in fullweb.io issue #85

How to delete lines containing a given string?

Just like last week, where we wanted to replace a string, we can use sed for this task:

sed '/pouet/d' file.txt

This will output file.txt on stdout without the lines containing pouet.

On Linux systems, you can add the -i option to delete the lines inplace. On Mac systems you can use -i .bak to also delete the lines inplace, but you need to tell how to name the backup of the original file (named file.txt.bak in this example).

@saschalalala
Copy link

I like grep -v word file.txt > file_without_word.txt

@nepsilon
Copy link
Author

nepsilon commented Feb 3, 2017

@saschalalala that works too 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment