Delete specific line number(s) from a text file using sed?
I want to delete one or more specific line numbers from a file. How would I do this using sed?
If you want to delete lines 5 through 10 and 12:
sed -e '5,10d;12d' file
This will print the results to the screen. If you want to save the results to the same file:
sed -i.bak -e '5,10d;12d' file
This will back the file up to file.bak
, and delete the given lines.
还有awk
awk 'NR!~/^(5|10|25)$/' file
$ cat foo
1
2
3
4
5
$ sed -e '2d;4d' foo
1
3
5
$
链接地址: http://www.djcxy.com/p/77064.html
上一篇: 正则表达式来匹配EOF
下一篇: 使用sed从文本文件中删除特定的行号?