这就是我在第一个模式之前添加文本的方式,我想在最后一个模式之后添加
FILE_NAME="folder/myfile.c++"
STR_TO_ADD="string that i want to add"
PATTERN="banana"
ed $FILE_NAME 2>NULL 1>NULL<<EOF
/^$PATTERN
-1
a
$STR_TO_ADD
.
wq
EOF
文件
banana
apple
banana
one
two
three
预期产出
banana
apple
banana
string that i want to add
one
two
three