1.删除指定行
删除第三行
sed '3d' test.txt
删除二到四行
sed '2,4d' test.txt
删除二到剩下行
sed '2,$d' test.txt
删除匹配/num 1/的行
sed '/num 1/d' test.txt
删除匹配/1/,/3/的之间行(包括指定的行),第一个匹配打开了删除功能,第二个匹配关闭了删除功能
sed '/1/,/3/d' test.txt
需要注意的是,一旦删除模式打开,如果没有停止模式,后续的文本都会被删除,比如
This is line number 1.
This is line number 2.
This is line number 3.
This is line number 4.
This is line number 1 again.
This is text you want to keep.
This is the last line in the file.
后面两句也会被删除