I have a text file that have about 10 columns, 7 of those are date/time stamps (year, month, day, hour, minute, second, centisec). So the data looks roughly like...
User[TAB]System[TAB]Year[TAB]Month[TAB]Day ... centisec[TAB]Message Sorry for the horrible formatting, but I hope this gives you the idea.
So if I wanted to sort the file by years, I could use this
sorted_lines = sorted(unsortedfile,key=lambda l: int(l.split('\t')[2])) Take the unsorted file, split the lines by tabs, 3rd column, change it to an int and sort by that. I could do the same thing for any one column.
What I'm looking for is a better way to sort this by all the date/time columns. So sort by Year, then by month, then by day... etc
I can think of a few complicated ways of doing this (reading each line combining all the columns, sorting it... or doing a recursive sort by each column), but I'm hoping someone has a simpler, more pythonic, way to do the same thing.