Syntactic Confectionery Delight | |
PerlMonks |
Re: sorting a file - multilevelby jethro (Monsignor) |
on Jun 14, 2008 at 02:24 UTC ( [id://692043]=note: print w/replies, xml ) | Need Help?? |
Has the first number always the same length? If yes, you can use unix sort (like runrig suggested) as a first step. Afterwards the file is now sorted by your first and secondary criteria. Only lines with same first and secondary columns are still unsorted, but they are on consecutive lines and small enough to be sorted in memory So your program should now read lines from the presorted file and collect lines with equal first and second columns. Sort them with perl sort on the 10th column and write them to a new file. The new file is now sorted to your criterias. If unix sort doesn't change the ordering of lines that are equal (which I believe it does, but I'm not sure) then you can do the complete sorting with unix sort. Just use sort with parameter -k=10 to first sort the file by the 10th column, then with -k=1,2 to sort by the first and second column.
In Section
Seekers of Perl Wisdom
|
|