awk clarification

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

awk clarification

vamsi
I have temp.txt  file and i want to change the delimiter from | to , and file name also to be changed to temp.csv.I have used below command no error but i am not getting required o/p.I have already read the post
8 examples to change the delimiter of a file in Linux  but i want  to know what is the problem with my command
a|b|c
1|2|3

awk 'BEGIN{FS="|";OFS=","} {print $0}' temp.txt>temp.csv
Reply | Threaded
Open this post in threaded view
|

Re: awk clarification

Guru
Administrator
Like this:

awk 'BEGIN{FS="|";OFS=",";}{$1=$1;print $0;}'
Reply | Threaded
Open this post in threaded view
|

Re: awk clarification

vamsi
ok thanks.what is need for $1=$1;.could you please elaborate on this and  i am printing the entire record with $0.
Reply | Threaded
Open this post in threaded view
|

Re: awk clarification

Guru
Administrator
When we try to change the output field separator, for it to take effect, any one of the columns should be updated/changed. So, we just do a dummy update by doing $1=$1.
Reply | Threaded
Open this post in threaded view
|

Re: awk clarification

vamsi
thanks guru