Day 55: Removing line with sed

27 Sep 2017

For a basic use of sed, please read the previous post ;)

2 ways for removing a line with sed:

With line number

$ cat foobar.txt
foo
bar
baz

# Removes line 2
$ cat foobar.txt | sed '2d'
foo
baz

:bulb: Please note that the first line is the line 1 (not 0).

With pattern

$ cat foobar.txt
foo
bar
baz

# Removes lines containing 'ba'
$ cat foobar.txt | sed '/ba/d'
foo