当前位置: 技术问答>linux和unix
关于awk替换
来源: 互联网 发布时间:2015-10-03
本文导语: 我有个文件abc,内容如下: 10506117915010137570,0,2010000sm2,1960,CHAR 10506117915010137571,70,2010000sm2,3000,CHAR 10506117915010137572,108,2010000sm2,1960,CHAR 10506117915010137573,200,2010000sm2,3000,CHAR ... 想用SHELL运行后,把文件abc中的逗号“,”变成T...
我有个文件abc,内容如下:
10506117915010137570,0,2010000sm2,1960,CHAR
10506117915010137571,70,2010000sm2,3000,CHAR
10506117915010137572,108,2010000sm2,1960,CHAR
10506117915010137573,200,2010000sm2,3000,CHAR
...
想用SHELL运行后,把文件abc中的逗号“,”变成TAB键,
也就是结果应该为:
10506117915010137570 0 2010000sm2 1960 CHAR
10506117915010137571 70 2010000sm2 3000 CHAR
10506117915010137572 108 2010000sm2 1960 CHAR
10506117915010137573 200 2010000sm2 3000 CHAR
...
听说用awk可以实现,请赐教,谢谢!
10506117915010137570,0,2010000sm2,1960,CHAR
10506117915010137571,70,2010000sm2,3000,CHAR
10506117915010137572,108,2010000sm2,1960,CHAR
10506117915010137573,200,2010000sm2,3000,CHAR
...
想用SHELL运行后,把文件abc中的逗号“,”变成TAB键,
也就是结果应该为:
10506117915010137570 0 2010000sm2 1960 CHAR
10506117915010137571 70 2010000sm2 3000 CHAR
10506117915010137572 108 2010000sm2 1960 CHAR
10506117915010137573 200 2010000sm2 3000 CHAR
...
听说用awk可以实现,请赐教,谢谢!
|
cat abc | sed 's/,/TAB/g'
|
不用awk也可以,用vi打开abc文件,在命令模式下输入
:%s/,/TAB(按Tab键)/g
回车就可以了。
:%s/,/TAB(按Tab键)/g
回车就可以了。
|
sed "s/,/ /g" src_file > dst_file