ggupta
ggupta

Reputation: 59

shell script to print and sort the date column in csv

I have a large csv file having the date column at column number 4 of csv file the format of data is format YYYY-MM-DD HH:MM:SS.0000000 +11:30 I want to sort this date in ascending order and dump it into the another csv file container top 10 entries or print.

I have tried with the following command:

sort -t, nk4 file.csv >/tmp/s.csv

Upvotes: 0

Views: 1500

Answers (1)

SLePort
SLePort

Reputation: 15461

It should be sort -t, -nk4 (- is missing before options).

To output only the 10 first lines, you can pipe your sort to head:

sort -t, -nk4 file.csv | head -n10 > /tmp/s.csv

The same maybe a bit more readable:

sort -t ","  -k 4 -n file.csv | head -n10 > /tmp/s.csv

head -n10 is to print only the 10 first line of the sort output.

Upvotes: 1

Related Questions