Skip to content

Instantly share code, notes, and snippets.

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

Good reference: https://likegeeks.com/sed-linux/

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