Search code examples
shellunixawkcut

UNIX : TEXT PROCESSING ISSUE USING CUT


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.


Solution

  • 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