【问题标题】:A sed result to be inserted into another file要插入另一个文件的 sed 结果
【发布时间】:2021-06-24 15:18:38
【问题描述】:

如何将 sed 结果直接插入到另一个文件中的模式字符串的特定点?如下只是澄清说明:

sed -E 's/foo/foo\0bar/' foo | sed -E '/^bar$/i{ }' bar   # ?

所以在 bar 文件中插入 { } 行的位置是 bar 字符串

【问题讨论】:

  • sed -i 's/foo/foo\0bar\n{ }/' file?为什么使用-E?如果第二个sed 是从bar 读取的,为什么还要管道sed 输出?而's/foo/foo\0bar/ 缺少'。为什么要插入一个零字节?

标签: string sed


【解决方案1】:

这可能对你有用(GNU sed):

sed '/bar/e sed -n "\\#foo#p" file1' file2

这将在 file1 中匹配 foo 的行插入到 file2 中匹配 bar 的行之前。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2019-02-19
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    相关资源
    最近更新 更多