添加spa
$sed –i '1a\contentDown' myfile -----------在第1行下面插入contentDown.net
$sed '/xiaoxiao/a\mingming' myfile --------在xiaoxiao對應行下面插入mingmingblog
$sed –i '4i\contentUp' myfile -------- 在第4行上面插入contentUptest
$sed –i '5c\ myline5' myfile -------- 在第5行內容改爲myline5sed
$ sed 's/^/head&/g' myfile ------- 每行的頭添加字符headfile
$ sed 's/$/&foot/g' myfile ------- 每行的行尾添加字符foot文件
補充:1."^"表明行首,"$"表明行尾co
2、's/$/&foot/g'中的字符g表明每行出現的字符所有替換,若是想在特定字符處添加,g就有用了,不然只會替換每行第一個,而不繼續日後找了字符
刪除
$ sed '2d' myfile -----刪除myfile文件的第二行。
$ sed '2,$d' myfile -----刪除myfile文件的第二行到末尾全部行。
$ sed '$d' myfile -----刪除myfile文件的最後一行。
$ sed '/test/'d myfile -----刪除myfile文件全部包含test的行。
sed更多操做可點擊->http://my.oschina.net/u/2473136/blog/610740