Reputation: 1220
I have a CSV File '1.txt' with fields as
#1.txt
Name,Activity,Address,URL,Number,Company
and I wanted to be in the format
#2.txt
Name,URL,Address,Activity,Number,Company
I tried using cut
cut -d, -f1,4,3,2,5,6 1.txt > 2.txt
The output ( 2.txt
) remains the same as Input.
Can some one help me on this ? As file size is too large(500000 Lines) to process in sheets/excel.
Upvotes: 0
Views: 74
Reputation: 203625
No point hard-coding every field number, just swap the 2 fields you care about:
$ awk 'BEGIN{FS=OFS=","} {t=$2;$2=$4;$4=t} 1' file
Name,URL,Address,Activity,Number,Company
Upvotes: 3
Reputation: 909
According to the cut
manpage, selected input is written in the same order that it is read. So you have to use awk instead:
awk -v FS=, -v OFS=, '{print $1,$4,$3,$2,$5,$6}' < 1.txt > 2.txt
Upvotes: 3