1,sed '3d' test.txt : 把test.txt中的第三行刪除
2,sed 『3a hello world』 test.txt: 在test.txt的第三行後面新增"hello world"這一行
3,sed 『3i hello world』 test.txt: 在test.txt的第三行前面面新增"hello world"這一行
4,sed 『3,5c hello world』 test.txt: 在test.txt的第3-5替換為hello world
4,sed -n 『3,5p』 test.txt: test.txt的3-5行列印出來
以上是以整行進行編輯的,並且都是通過制定行的編號進行操作,下面是以行為單位對,行中的部分資料進行替換,v
5.sed 『s/要被替換的字串/新的字串/g』:比如:
sed 's/^.*addr://g' : 把開頭到 addr: 這段字串替換成 『 』,即刪除
sed 's/goodbye.*$//g' : 把goodbye到結尾 這段字串替換成 『 』,即刪除
注意:. *正規表示式的使用
sed使用舉例
刪除 d命令 sed 2d example 刪除example檔案的第二行。sed 2,d example 刪除example檔案的第二行到末尾所有行。sed d example 刪除example檔案的最後一行。sed test d example 刪除example檔案所有包含test的行。替換...
sed常用用法技巧舉例
1.sed替換換行符及標籤的使用 echo a,b,c,d sed s n g sed s n g 解析 以上命令實現不了替換換行符,這跟sed的行處理方式有關,sed讀取一行時,會先把換行符去掉,處理完後再新增上,所以是無法使用上面的命令進行換行符替換的,必須使用sed中的其它命令來完成。上面的恢...
sed應用要點
sed使用方式 sed f myscript.sed input file sed some sed commands input file myoutfile 基本sed編輯命令 p 列印匹配行 顯示檔案行號 a 在定位行號後附加新文字資訊 i 在定位行號前插入新文字資訊 d 刪除定位行 c 用新...