【发布时间】:2019-07-08 10:12:03
【问题描述】:
这就是我在 first 模式之前添加文本的方式, 我想在 last 模式之后添加
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
【问题讨论】:
-
非常感谢,还有一个小问题。模式搜索仅在从行首开始时才找到该行,我如何知道开头未知?