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
原创文章 96 获赞 4 访问量 2166

猜你喜欢

转载自blog.csdn.net/weixin_46380571/article/details/105748645
sed