Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robbinhan/6b63c18b25234a92e99a76f636f5b1be to your computer and use it in GitHub Desktop.
Save robbinhan/6b63c18b25234a92e99a76f636f5b1be 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).

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