在linux下,文本替换是vim编辑器常用的命令
s/1/2/:将第一行(默认)匹配到的第一个“1”替换成“2”
10 s/1/2/:将第十行匹配到的第一个“1”替换成“2”
% s/1/2/:将所有行中匹配到的第一个“1”替换成“2”
% s/1/2/g:将所有行中匹配到的“1”替换成“2”
而sed替换命令和vim编辑器类似
①:sed 显示替换信息,不改变文本内容
[root@localhost ~]# cat 1.txt
21111111222222333333333333
1234
234
[root@localhost ~]# sed 's/1/2/' 1.txt
22111111222222333333333333
2234
234
[root@localhost ~]# cat 1.txt
21111111222222333333333333
1234
234
[root@localhost ~]#
②:sed 修改文本内容
[root@localhost ~]# cat 1.txt
21111111222222333333333333
1234
234
[root@localhost ~]# sed -i 's/1/2/' 1.txt
[root@localhost ~]# cat 1.txt
22111111222222333333333333
2234
234
[root@localhost ~]#
完!