【发布时间】:2021-04-11 21:20:07
【问题描述】:
我有一个包含以下内容的变量:
k1065-betfirst-4ccc6a2cf196 (192.168.255.46) is off-line k1164-betfirst-4ccc6a8ff0be (192.168.255.54) is off-line K1165-BetFirst-4ccc6a2cf343 (192.168.255.26) is off-line K1185-BetFirst-4ccc6aba7af7 (192.168.255.18) is off-line k1331-betfirst-448a5bb71eb8 (192.168.255.38) is off-line
我需要在“line”换行符之后插入。为此,我使用 sed:
echo -e $mailbody | sed 's/line/\n&/g' | tee -a hosts2.txt
但它在“行”之前插入换行符:
k1065-betfirst-4ccc6a2cf196 (192.168.255.46) is off-
line k1164-betfirst-4ccc6a8ff0be (192.168.255.54) is off-
line K1165-BetFirst-4ccc6a2cf343 (192.168.255.26) is off-
line K1185-BetFirst-4ccc6aba7af7 (192.168.255.18) is off-
line k1331-betfirst-448a5bb71eb8 (192.168.255.38) is off-
line
谁能给我一个提示,如何重写sed,在“line”之后写换行符?
【问题讨论】:
-
那么,交换
\n和&?sed 's/line/&\n/g'?