小编Rog*_*man的帖子

如何在第三个文件中用 in.txt 替换 out.txt 的内容?

我有三个文件,main.txtout.txtin.txt. 我想用 的内容替换每次出现的out.txtinmain.txt内容in.txt

out.txtin.txt可以包含多行和各种特殊字符。如何正确读取和转义这些字符串?

这是一个包含一些边缘情况的示例,例如特殊字符、重复匹配、不完整匹配、重叠匹配。

main.txt:

foo
Replace these
three lines
with some $.*\'"& in it
bar
Replace these
three lines
with some $.*\'"& in it
Replace these
three lines
with some $.*\'"& in it

three lines
Replace these
three lines
three lines
with some $.*\'"& in it
baz
Run Code Online (Sandbox Code Playgroud)

out.txt:

Replace these
three lines
with some $.*\'"& in it
Run Code Online (Sandbox Code Playgroud)

in.txt:

Replacement …
Run Code Online (Sandbox Code Playgroud)

sed awk perl text-processing

-1
推荐指数
1
解决办法
128
查看次数

标签 统计

awk ×1

perl ×1

sed ×1

text-processing ×1