使用sed在特定行插入状态

时间:2021-02-01 01:39:18

I have the following on my bash

我的bash上有以下内容

DOMAIN=myserver
sed -i '34 d' $PATH
sed -i -e '34i$smtpServerAddress      = '${DOMAIN}.com';   '\' $PATH

result is:

结果是:

$smtpServerAddress      = myserver.com;   '

but I'd like to have:

但是我希望:

$smtpServerAddress      = 'myserver.com';

what's wrong?

怎么了?

Thanks

谢谢

1 个解决方案

#1


1  

No need of two sed. You can make it as one like this.

不需要两个sed。你可以像这样做一个。

sed -i.bak "34s/.*/\$smtpServerAddress      = '${DOMAIN}.com';/g"  $PATH

(OR)

(要么)

As per your sed,

根据你的sed,

sed -i.bak "34i\$smtpServerAddress      = '${DOMAIN}.com';"  $PATH

#1


1  

No need of two sed. You can make it as one like this.

不需要两个sed。你可以像这样做一个。

sed -i.bak "34s/.*/\$smtpServerAddress      = '${DOMAIN}.com';/g"  $PATH

(OR)

(要么)

As per your sed,

根据你的sed,

sed -i.bak "34i\$smtpServerAddress      = '${DOMAIN}.com';"  $PATH