删除与SED或AWK从文件中的行 [英] Delete lines from file with SED or AWK
本文介绍了删除与SED或AWK从文件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我见过许多变化,对如何解决这些问题,3非常困惑。
- 删除从文件中除第一个所有行
- 删除文件从一排的行号
- 删除从文件中的行与一系列行号
解决方案
使用sed的:
删除第一行:
sed的1D文件名
删除第10行:
sed的10D文件名
删除线#5到10
的sed'5,10d'文件名
以上所有sed命令将写在标准输出的输出,如果你想,你可以重定向到另一个文件或使用sed的 -i
标记内联编辑文件。
Ive seen many variations, very confused on how to solve these 3 problems.
- deleting all rows except the first from a file
- deleting a row from file with a line number
- deleting rows from a file with a range of line numbers
解决方案
Using sed:
Delete 1st line:
sed '1d' file-name
Delete 10th line:
sed '10d' file-name
Delete line # 5 to 10
sed '5,10d' file-name
All above sed commands will write output on stdout that you can redirect to another file if you want or use -i
flag of sed to inline edit the file.
这篇关于删除与SED或AWK从文件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文