【问题标题】:Delete specific lines using sed in multiple files [closed]在多个文件中使用 sed 删除特定行 [关闭]
【发布时间】:2014-04-18 21:42:53
【问题描述】:

我想知道如何用 sed 删除多个 html 文档的前 196 行。 我的目录结构如下:

【问题讨论】:

  • 如果您尝试删除已知范围的行(例如第 1 到 196 行,如您的问题),我不确定 sed 是正确的工具。
  • 你会推荐什么工具?我还使用 sed 将某些行替换为其他字符串
  • tail 将是选择文件尾部行的正确工具。 sed 不能处理字符串,只能处理 RE,如果需要替换字符串,则需要使用 awk。

标签: linux bash file text sed


【解决方案1】:
find /rootdir/ -name index.html -exec sed -i '1,196d' {} \;

【讨论】:

  • 它没有在所有文件夹中运行,会是这个样子吗?
  • @user3550278 它将在/rootdir/ 中递归地在所有 index.html 文件上运行,例如/rootdir/foo/bar/index.html
  • @user3550278 要在多个html 文件上执行此操作,您只需将-name index.html 修改为-name "*.html"
  • 当我运行它时它会这样做i.imgur.com/9xjnibQ.png
  • 你的网站根目录是/rootdir吗?如果没有,请使用适当的目录名称