当前位置: 技术问答>linux和unix
问一个简单的shell问题:如何将一个文件中的字符串A全部用另外一个字符串B替换?
来源: 互联网 发布时间:2015-05-25
本文导语: 用shell命令实现。 | gawk '$0!~/A/{print } gsub('/A/',"B',$0){print}' your_file_name [>destfile] for example,let A=aaaa,B=bbbb,we can run this command gawk '$0!~/aaaa/{print} gsub('/aaaa/',"bbbb",$0){print}' myfile >destf...
用shell命令实现。
|
gawk '$0!~/A/{print } gsub('/A/',"B',$0){print}' your_file_name [>destfile]
for example,let A=aaaa,B=bbbb,we can run this command
gawk '$0!~/aaaa/{print} gsub('/aaaa/',"bbbb",$0){print}' myfile >destfile
for example,let A=aaaa,B=bbbb,we can run this command
gawk '$0!~/aaaa/{print} gsub('/aaaa/',"bbbb",$0){print}' myfile >destfile
|
sed
|
In fact,it's easy if you use vim ( :s/A/B/g)