cat 在正则表达式后行到文件中

cat lines into file after regex

我想将下面的信息添加到文件 usr/local/nagios/etc/hosts.cfg 中,但想在 hosts.cfg 文件中的##company 下面添加。我的设置脚本将包含需要添加的信息

我花了几个小时试图让 sed 在标记后的文件中添加一行,但无济于事

define host{
use                         linux-box
host_name                   $host_name
alias                       $alias
address                     $ip 
parents                     $parent
notification_period         24x7
notification_interval       5
}

以前我用过 cat <> /路径/文件名 紧急时间 但现在我需要在文件中的特定位置执行此操作

给出以下 file

# some content

###company

如果我运行以下命令:

sed -i 's/###company/&\ndefine host {\nuse host\nhost_name HOSTNAME/' file

现在file的内容是:

# some content

###company
define host {
use host
host_name HOSTNAME

这是您要找的吗?