Reputation: 55
I have the following awk script:
BEGIN { FS=","; OFS=","; }
{ print $4,$1,$2; }
and this is my input file:
a1,a2,a3,a4
b1,b2,b3,b4
I'd expect it to return:
a4,a1,a2
b4,b1,b2
But it doesn't. Instead I get:
,a1,a2
,b1,b2
Why is that?
Upvotes: 2
Views: 1251
Reputation: 784998
Most likely it is due to DOS
line ending \r
at the end of each line. Use this gnu-awk
command to get the right output:
awk -v RS='\r?\n' 'BEGIN { FS=OFS="," } { print $4,$1,$2 }' file
a4,a1,a2
b4,b1,b2
Upvotes: 6