【问题标题】:Sed command replicating substitution twicesed 命令复制替换两次
【发布时间】:2021-08-14 09:03:06
【问题描述】:

我有一个简单的文件,内容存储在 temp.txt 中

Here I lay in the depths of hell waiting to be rescued by my charming warrior.

一旦我使用 sed 命令替换

sed -i "s/hell/HELL/p" ./temp.txt

这是我得到的结果

Here I lay in the depths of HELL waiting to be rescued by my charming warrior.
Here I lay in the depths of HELL waiting to be rescued by my charming warrior.

有什么建议吗?

【问题讨论】:

    标签: linux sed terminal


    【解决方案1】:

    /p 标志复制该行。因此,如果您只想替换该事件,请避免使用它。所以命令将是:

    sed -i "s/hell/HELL/" ./temp.txt
    

    您的文件将是:

    Here I lay in the depths of HELL waiting to be rescued by my charming warrior.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 2020-09-22
      • 1970-01-01
      • 2022-01-10
      • 2019-02-11
      • 2018-09-16
      相关资源
      最近更新 更多