由于/ r代表读取文件,请使用:
sed '/First/r file1.txt' infile.txt
为就地版添加-i(即sed -i’/ First / r file1.txt’infile.txt).
sed 's/first/last/Ig' file
如评论中所示,上述解决方案仅仅是在模式之后打印给定的字符串,而不考虑第二模式.
要这样做,我会去拿一个标志的awk:
awk -v data="$(
鉴于这些文件:
$cat patt_file
This is text to be inserted
$cat file
Some Text here
First
First
Second
Some Text here
First
Bar
让我们运行命令:
$awk -v data="$(
Some Text here
First #
First
This is text to be inserted #
Second
Some Text here
First #
Bar