I have a csv input file where I want to extract specific fields. When I cat that file into mawk using the {FS=","} within the brackets, the first line of output is as if the field separator was still a space instead of the comma that I specified. From the second line onwards, the comma field separator is honoured.
The first three lines of output from the command I am using are:
$ cat LUN.csv | awk '{FS=","} {print $2","$5","$14","$17","$20","$23","$26","$29","$32","$35","$77","$78","$79","$80","$81","$82","$83","$84","$85","$86","$87","$88","$89","$90","$91","$92","$93","$94","$95","$96","$97","$98}'
60,5;,naa.600601605d212700a1c3b23a8a6ae011;,naa.600601605d212700a1c3b23a8a6ae011;,naa.600601605d212700a1c3b23a8a6ae011],06/02/2014,,,,,,,,,,,,,,,,,,,,,,,,,,,
06/02/2014 12:05:22,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
06/02/2014 12:07:36,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
If I try the command using the -F "," flag instead the first line of output also has the comma field separator honoured.
The first three lines of output from the command I am using are:
$ cat LUN.csv | awk -F "," '{print $2","$5","$14","$17","$20","$23","$26","$29","$32","$35","$77","$78","$79","$80","$81","$82","$83","$84","$85","$86","$87","$88","$89","$90","$91","$92","$93","$94","$95","$96","$97","$98}'
06/02/2014 12:02:59,0.158562,0.106358,3.061710,0.102991,38.801684,2.717995,0.003367,10.031008,0.343715,0,0,0,0,218,10,16,270,0,0,0,0,0,0,47,12,0,2,4,0,0,0
06/02/2014 12:05:22,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
06/02/2014 12:07:36,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
I would expect that the behaviour of both would be the same, and specifically that of the {FS=","} would be applied to the first line as well as all following lines.
The attached file is the head of the file I am using so you can test.
The version I am using is on kubuntu 13.10, the version information output is:
$ mawk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
I have a csv input file where I want to extract specific fields. When I cat that file into mawk using the {FS=","} within the brackets, the first line of output is as if the field separator was still a space instead of the comma that I specified. From the second line onwards, the comma field separator is honoured. ,"$14", "$17"," $20","$ 23","$26" ,"$29", "$32"," $35","$ 77","$78" ,"$79", "$80"," $81","$ 82","$83" ,"$84", "$85"," $86","$ 87","$88" ,"$89", "$90"," $91","$ 92","$93" ,"$94", "$95"," $96","$ 97","$98} ' 600601605d21270 0a1c3b23a8a6ae0 11;,naa. 600601605d21270 0a1c3b23a8a6ae0 11;,naa. 600601605d21270 0a1c3b23a8a6ae0 11],06/ 02/2014, ,,,,,,, ,,,,,,, ,,,,,,, ,,,,, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0
The first three lines of output from the command I am using are:
$ cat LUN.csv | awk '{FS=","} {print $2","$5"
60,5;,naa.
06/02/2014 12:05:22,
06/02/2014 12:07:36,
If I try the command using the -F "," flag instead the first line of output also has the comma field separator honoured. ,"$14", "$17"," $20","$ 23","$26" ,"$29", "$32"," $35","$ 77","$78" ,"$79", "$80"," $81","$ 82","$83" ,"$84", "$85"," $86","$ 87","$88" ,"$89", "$90"," $91","$ 92","$93" ,"$94", "$95"," $96","$ 97","$98} ' 0.158562, 0.106358, 3.061710, 0.102991, 38.801684, 2.717995, 0.003367, 10.031008, 0.343715, 0,0,0,0, 218,10, 16,270, 0,0,0,0, 0,0,47, 12,0,2, 4,0,0,0 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0
The first three lines of output from the command I am using are:
$ cat LUN.csv | awk -F "," '{print $2","$5"
06/02/2014 12:02:59,
06/02/2014 12:05:22,
06/02/2014 12:07:36,
I would expect that the behaviour of both would be the same, and specifically that of the {FS=","} would be applied to the first line as well as all following lines.
The attached file is the head of the file I am using so you can test.
The version I am using is on kubuntu 13.10, the version information output is:
$ mawk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
compiled limits:
max NF 32767
sprintf buffer 2040