I have a csv file which I need to order based on the timestamp. It is the third column in the csv and I am using below commands to sort:
awk \'NR<2{print $_;n
Try this:
sort -rft',' -k3 merged.csv
The below should work
awk 'NR<2{print $_;next}{ print $_ | "sort -t, -k3.8,3.11rn -k3.1,3.3rM -k3.5,3.6rn -k3.12rd" }'
The 'awk' snippet passes all lines except header to the sort command. The order of the keys is important here :
k3.8,3.11rn
extracts the year part of the column and reverse sorts
k3.1,3.3rM
extracts the first 3 characters in column three to be reverse monthly sorted and the rest we do a reverse dictionary sort
k3.5,3.6rn
extracts the day and reverse sort and finally we do the same for time
I will try to sort by date and then by time
awk -F"," '{print $3,$1,$2}' file.csv | sort -d' ' -k 1d -k 2d
BTW, it would be great if you just share a small section of your file. :)