简体   繁体   English

AWK在输出文件中的分隔符

[英]AWK's delimiter in output file

My Input file is like : 我的输入文件就像:

1,mad,retl,231,tcs
2,vais,
3,ram,bfs
4,sam,ins
5,tina,bfs

I m not sure about number of columns in my output. 我不确定输出中的列数。 O/P file : O / P文件:

1|mad|retl|231|tcs
2|vais|
3|ram|bfs
4|sam|ins
5|tina|bfs

I tried with code : 我尝试使用代码:

$ awk 'BEGIN {FS=",";OFS="|"} {print $0}' INPUT_FILE

The result is comma seperated. 结果以逗号分隔。 Can any assist 可以帮忙吗

Simply you could try the below. 您只需尝试以下方法。

$ awk '{gsub(/,/,"|")}1' file
1|mad|retl|231|tcs
2|vais|
3|ram|bfs
4|sam|ins
5|tina|bfs

OR 要么

$ awk 'BEGIN{FS=",";OFS="|"}{$1=$1}1' file
1|mad|retl|231|tcs
2|vais|
3|ram|bfs
4|sam|ins
5|tina|bfs

With sed : sed

sed 's/,/|/g' File

Just substitute , with | 刚刚替补,| globally. 全球。

With tr : tr

tr ',' '|' < File

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM