【发布时间】:2021-05-20 04:21:46
【问题描述】:
我的目标是在文件 (file1) 中找到一个字符串,并将其整行替换为另一个文件 (file2) 中特定行的内容(在此示例中为第 3 行)。据我了解,我需要使用 RegEx 来完成第一部分,然后使用第二个 sed 命令来存储 file2 的内容。 sed 绝对不是我的强项,所以我希望这里有人可以帮助一个菜鸟!
到目前为止我有:
sed -i '/^matching.string.here*/s' <(sed '3!d' file2) file1
编辑
示例文件1:
string one
string two
matching.string.here.
string three
示例文件2:
alt string one
alt string two
alt string three
file1 中的预期结果:
string one
string two
alt string three
string three
【问题讨论】:
-
您能否发布一些来自这两个文件的数据示例以及您预期结果的摘录?