小编Rob*_*hoy的帖子

根据字符串列表和相应替换列表替换文件中的字符串

我正在尝试替换 a 中的字符串file A

Hello Peter, how is your dad? where is mom? 
Run Code Online (Sandbox Code Playgroud)

要替换的字符串在file B

Peter
dad
mom
Run Code Online (Sandbox Code Playgroud)

和他们相应的替代品在file C

John
wife
grandpa
Run Code Online (Sandbox Code Playgroud)

预期结果:

Hello John, how is your wife? where is grandpa?
Run Code Online (Sandbox Code Playgroud)

我可以编辑file Afile B使用 in 中相应行中的值替换 in中的值file C吗?

到目前为止我做了什么:

 cat 1.txt | sed -e "s/$(sed 's:/:\\/:g' 2.txt)/$(sed 's:/:\\/:g' 3.txt)/" > 4.txt
Run Code Online (Sandbox Code Playgroud)

如果file B& 中只有file C一行,它会起作用,如果有多于一行,它将不起作用。

sed awk perl text-processing

5
推荐指数
2
解决办法
7846
查看次数

标签 统计

awk ×1

perl ×1

sed ×1

text-processing ×1