首页 > 解决方案 > sed 命令复制替换两次

问题描述

我有一个简单的文件,内容存储在 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.

有什么建议么?

标签: linuxsedterminal

解决方案


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

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

你的文件将是:

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

推荐阅读