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