Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sort sort a file with date field by date 1

Status
Not open for further replies.

ljsmith91

Programmer
May 28, 2003
305
US
I have not sorted in awhile with the Unix sort command. I can't seem to get this file sorted by the date field or the 3rd item on each file line. Here is the file content:

0,0,1,6 9840 2006-09-30
0,0,9,7 9840 2006-09-26
0,1,7,13 9840 2006-09-26
0,1,8,16 9840 2006-09-26
0,1,9,12 9840 2006-09-26
0,1,10,12 9840 2006-10-04
0,1,10,13 9840 2006-10-04
0,1,10,15 9840 2006-09-26
0,2,10,15 9840 2006-09-26
0,2,10,16 9840 2006-09-26
0,3,9,8 IBM-LTO-2 2006-09-26
0,4,4,14 IBM-LTO-2 2006-09-26
0,4,5,17 IBM-LTO-3 2006-10-03
0,4,5,18 IBM-LTO-3 2006-10-03
0,4,5,19 IBM-LTO-3 2006-10-03
0,4,9,6 IBM-LTO-2 2006-09-26

I tried "sort +2n my.file > mysorted.file" but it didn't work. I tried several variations and differnt things and I am having no success sorting this file by the date field. Can anyone give me the syntax of the sort command that I need for this? Thanks for any help.
 
Why not simply this ?
sort +2 my.file > mysorted.file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I just tried it and it still not doing what I need. here are the reults of that sort:

0,0,9,7 9840 2006-09-26
0,1,10,15 9840 2006-09-26
0,1,7,13 9840 2006-09-26
0,1,8,16 9840 2006-09-26
0,1,9,12 9840 2006-09-26
0,2,10,15 9840 2006-09-26
0,2,10,16 9840 2006-09-26
0,0,1,6 9840 2006-09-30
0,1,10,12 9840 2006-10-04
0,1,10,13 9840 2006-10-04
0,3,9,8 IBM-LTO-2 2006-09-26
0,4,4,14 IBM-LTO-2 2006-09-26
0,4,9,6 IBM-LTO-2 2006-09-26
0,4,5,17 IBM-LTO-3 2006-10-03
0,4,5,18 IBM-LTO-3 2006-10-03
0,4,5,19 IBM-LTO-3 2006-10-03


It should be easier. Any ideas ?
 
And this ?
sort -b +2 my.file > mysorted.file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

That did the trick. I wouldn't have found that....well...maybe after a week of research and failed attempts. Thanks so much.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top