sed在首次匹配前插入:
一:sed $'0,/a/ {/a/ i c\n}' file
二:sed '/a/ {i c\n; :loop; n; b loop}' file
Note: The a,i,c commands terminate on newlines, so you have to physically break the line in order to finish up the expression.
处理最后一次匹配情况时,可以使用tac先反转文件
sed在首次匹配前插入:
一:sed $'0,/a/ {/a/ i c\n}' file
二:sed '/a/ {i c\n; :loop; n; b loop}' file
Note: The a,i,c commands terminate on newlines, so you have to physically break the line in order to finish up the expression.
处理最后一次匹配情况时,可以使用tac先反转文件