我正在尝试使用 sed 在字符串匹配后插入一些文本,但我无法在附加文本中使用前导回车符。我有 ...
sed -i "/^#Comment to append text after/a \n[$username.conn]\nipAddress=$ipAddr\nportNumber=$portNum" file
我想在那个 3 行插入之前有一个回车,所以输出是......
#Comment to append text after
[$username.conn]
ipAddress=xxx.xxx.xxx.xxx
portNum=yyyy
但是将 a\n
放在 just 前面会[$username.conn]
导致前导 n...
#Comment to append text after
n[$username.conn]
ipAddress=xxx.xxx.xxx.xxx
portNum=yyyy
关于如何做到这一点的任何建议?