Linux下的sed流编辑器命令详解
命令示例: [root@master rh]# cat test.txt this is first line this is second line this is third line this is fourth line this fifth line happy everyday end a 命令 sed '1a \add one' test.txt 本例命令部分中的1表示第一行,同样的第二行写成2,第一行到第三行写成1,3,用$表示最后一行,比如2,$表示第二行到最后一行中间所有的行(包含第二行和最后一行)。 本例的作用是在第一行之后增加字符串”add one”,从输出可以看到具体效果。 sed '1,$a \add one' test.txt 本例表示在第一行和最后一行所有的行后面都加上”add one”字符串,从输出可以看到效果。 sed '/first/a \add one' test.txt 本例表示在包含”first”字符串的行的后面加上字符串”add one”,从输出可以看到第一行包含first,所以第一行之后增加了”add one” sed '/^ha.*day$/a \add one' test.txt 本例使用正则表达式匹配行,^ha.*day$表示以ha开头,以day结尾的行,则可以匹配到文件的”happy everyday”这样