linux常用命令之文本替换
1 vi
vi test_file
:%s/h/h1/g
注释:全文替换,将h替换为h1
:1,4s/h/h1/g
注释:将第1行到第4行的h替换为h1
:%s/\n/,/g
注释:将换行符替换为,
2 sed
sed -e 's/h/h1/g' test_file
注释:全文替换,将h替换为h1
sed -e '1,4s/h/h1/g' test_file
注释:将第1行到第4行的h替换为h1
sed ':a;N;$!ba;s/\n/,/g' test_file
注释:将换行符替换为,