【问题标题】:sed - insert text after other text [closed]sed - 在其他文本之后插入文本[关闭]
【发布时间】:2014-04-13 15:25:39
【问题描述】:

所以我有这行:

DirectoryIndex index.html index.html.var

我需要在DirectoryIndex之后使用sed命令插入'index.php'(我不想替换它,只插入'index.php')所以看起来像这样:

DirectoryIndex index.php index.html index.html.var

【问题讨论】:

  • 这应该是真的微不足道的。你有没有做过任何的尝试?
  • 虽然我认为有人会很乐意将解决方案摆在您面前,但我强烈建议您阅读manual

标签: linux bash sed scripting command


【解决方案1】:
sed -r 's/(DirectoryIndex)/\1 index.php/' file.txt 

【讨论】:

    【解决方案2】:

    将一些文本插入到与特定子字符串相关的行中涉及将子字符串替换为自身 + 新文本:

    sed 's/DirectoryIndex/& index.php/'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 2012-02-03
      相关资源
      最近更新 更多