这是我要更改的文件。我想在servers {下添加一个条目。

eap-radius {

    # Section to specify multiple RADIUS servers.
    servers {

    }
}

这就是我试过的
sed -i '/servers {/a\
server-a {
            accounting = yes
            secret = 123456
            address = 127.0.0.1
            auth_port = 1812
            acct_port = 1813
}
' /etc/strongswan.d/charon/eap-radius.conf

sed:-e表达式1,字符81:未终止的“s”命令

最佳答案

我认为你需要避开新的思路:

sed '/servers {/a\
        server-a {\
            accounting = yes\
            secret = 123456\
            address = 127.0.0.1\
            auth_port = 1812\
            acct_port = 1813\
        }
' ./test.txt

结果是(我也有点标签server-a块):
eap-radius {

    # Section to specify multiple RADIUS servers.
    servers {
        server-a {
            accounting = yes
            secret = 123456
            address = 127.0.0.1
            auth_port = 1812
            acct_port = 1813
        }

    }
}

在Ubuntu 14.04.5lts上测试,gnubashversion4.3.11(1)-发行版

10-07 18:40