Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 607 Bytes

File metadata and controls

59 lines (43 loc) · 607 Bytes

Use sed to remove line containing a string

The sed command can be used to remove lines containing a keyword.

Remove line containing string from standard input:

$ echo -e "1\n2\n3"
1
2
3
$ echo -e "1\n2\n3" | sed "/2/d"
1
3

Remove line containing string from a file:

$ echo -e "1\n2\n3" > myfile.txt
$ cat myfile.txt
1
2
3
$ sed -i "" "/2/d" myfile.txt
$ cat myfile.txt
1
3

Posted May 20, 2021.

https://www.darklaunch.com/2021/05/20/use-sed-to-remove-line-containing-a-string.html