0

文件是

AVAIL_CHECK_SECS=30
# we need at least one server
if [ -z "$1" ]; then
usage "Missing hostname parameter(s)"
fi

输出应该是

AVAIL_CHECK_SECS=30
# cache a copy of the agent jar for pushing to remote servers
# we need at least one server
if [ -z "$1" ]; then
usage "Missing hostname parameter(s)"
fi

我想在两行之间添加一行,即 # 缓存代理 jar 的副本以推送到远程服务器

4

2 回答 2

0

使用awk您可以执行以下操作:

awk 'NR==1 {$0=$0 "\n# cache a copy of the agent jar for pushing to remote servers"} 1' file
AVAIL_CHECK_SECS=30
# cache a copy of the agent jar for pushing to remote servers
# we need at least one server
if [ -z "$1" ]; then
usage "Missing hostname parameter(s)"
fi
于 2013-11-15T05:42:50.313 回答
0
sed -e '1a\
# cache a copy of the agent jar for pushing to remote servers' File

这按行号工作。您可以将 1 替换为/^AVAIL_CHECK_SECS/,或者1a通过/# we need/i在应放置行的位置之前或之后匹配行上的模式来完成。

于 2013-11-15T04:23:02.667 回答