sed -i 增加或删减注释#
1.某一行增加注释#
sed -i '3,4s/^/#/' yang >>>将第3,4行,行首添加注释#,yang为文件名
2.某一行删减注释#
sed -i '1,2s/^#//' yang >>>将第1,2行,行首删掉#,yang为文件名
3.替换某一行中的内容
sed -i '3s/8080/9000/' yang >>>将文件中,第三行的8080,替换成9000
4.替换文件中包含的某个内容
sed -i 's/8080/9000/g' yang >>>将整个文件中的8080,替换成9000
5.删除某一行末尾的某个字符
sed -i "9s|,$||" yang >>>将第9行末尾的【,】删掉,yang为文件名
例如:
sudo nano yang
ggggggApiBaseUrl: 'http://xxxx.xxcccv.com/v4',
改完后:
ggggggApiBaseUrl: 'http://xxxx.xxcccv.com/v4'
6.修改的同时备份文件
yang@ubuntu:~/ceshi$ cat test
hello bash world
hi~ tester
go go go go!
yang@ubuntu:~/ceshi$ sed -i.back "s/hello/HELLO/g" test
yang@ubuntu:~/ceshi$ ls
test test.back
yang@ubuntu:~/ceshi$ cat test
HELLO bash world
hi~ tester
go go go go!
yang@ubuntu:~/ceshi$ cat test.back
hello bash world
hi~ tester
go go go go!

浙公网安备 33010602011771号