删除与SED或AWK从文件中的行 [英] Delete lines from file with SED or AWK

查看:105
本文介绍了删除与SED或AWK从文件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过许多变化,对如何解决这些问题,3非常困惑。


  1. 删除从文件中除第一个所有行

  2. 删除文件从一排的行号

  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.

  1. deleting all rows except the first from a file
  2. deleting a row from file with a line number
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆