linux - 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.
有什么建议么?
解决方案
/p 标志复制该行。因此,如果您只想替换该事件,请避免使用它。所以命令将是:
sed -i "s/hell/HELL/" ./temp.txt
你的文件将是:
Here I lay in the depths of HELL waiting to be rescued by my charming warrior.
推荐阅读
- azure-devops - 删除包含无效字符的发布文件夹
- swift - 附近设备的iOS蓝牙mac地址
- java - 如果文件名模式与 Camel 不匹配,如何将文件移动到错误目录
- visual-studio - 如何在 VS Code 中使用标签包装选定的文本并有效地重复操作?
- php - 如何在php中的每个现有输出后添加逗号
- java - 自动装配泛型类的所有bean
- c# - WebBrowser 尝试下载本地 PDF,而不是显示它
- makefile - 如何在make中进行条件调试
- javascript - 使用“reduce”操作对象并生成数组
- html - 如何从日期选择器中设置日期以便能够保存 mvc 5