sed(筆記)

shell -x 調試腳本
[root@c7-44 ~]#  sed '2s/1$/2/' test.log   #1$代表最後一個
1 1 1 1
1 1 1 2
1 1 1 1
1 1 1 1

更改第三列爲2

[root@c7-44 ~]# cat test.log  | sed s/1/2/3
1 1 2 1
1 1 2 1
1 1 2 1
1 1 2 1

[root@c7-44 ~]# cat test.log 
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

[root@c7-44 ~]# sed '2s#1#3#g' test.log    #替換第二行  2s
1 1 1 1
3 3 3 3
1 1 1 1
1 1 1 1
[root@c7-44 ~]# sed 's#1#3#g' test.log    #替換全部  g
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
[root@c7-44 ~]# sed 's#1#3#2' test.log   #替換第2列
1 3 1 1
1 3 1 1
1 3 1 1
1 3 1 1
[root@c7-44 ~]# sed '2s#1#3#2' test.log    #替換第二行:2s 第二列: 2 
1 1 1 1
1 3 1 1
1 1 1 1
1 1 1 1
[root@c7-44 ~]# cat test.log  | sed s/1/2/3   #替換第三列
1 1 2 1
1 1 2 1
1 1 2 1
1 1 2 1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章