sed 替换指定行(备忘)

关于sed的详细命令见此链接:man.linuxde.net/sed

替换指定行

(1) 查找aaa.txt中包含xxxx的行号

LINE_NUM=$(sed -n '/xxxx/='  aaa.txt)
 (2)替换指定行号为yyyy
sed    $OPTS   "$LINE_NUM"'c  yyyy‘   aaa.txt
 
ps:因为我使用的场景中包含xxxx的行只有一行,如果多行还要进行判断
posted @ 2018-08-29 17:58  王的博客  阅读(8314)  评论(0)    收藏  举报