user3260018
user3260018

Reputation: 11

Sort a file based on first date time column

I have a file test.txt as follows:

2014-02-01 00:24:15.197213862   /opt/backup/000000010000006B00000015 10.10.68.37
2014-01-31 22:04:15.115246492   /opt/backup/000000010000006A000000F8 10.10.68.38
2014-01-31 22:39:15.099505954   /opt/backup/000000010000006B00000000 10.10.68.39

I need to sort the data based on time that is first column. The script should be executable on Centos 5 and 6.

Any idea please.

Thanks.

Upvotes: 1

Views: 166

Answers (1)

U2EF1
U2EF1

Reputation: 13279

You're in luck. Assuming all your dates are ISO style, you should be able to just run sort -k 1,2 test.txt, where -k option specifies you are sorting on first 2 collumns (in given order).

Upvotes: 3

Related Questions