Linux sort ignoring zeros Tags: Command Prompt Linux Last response: July 3, 2010 6:01 PM in Linux/Free BSD Share Anonymous July 2, 2010 4:16:51 PM Hi Guys... I`m using this command 'sort -rn >> /tmp/log.log' I want the latest date at the top of the file...this is ok from the 10th onwards.. but when you throw in 01 to 09 it puts these dates out of order... anyone have any ideas ?? I`ve scoured the net Derwood More about : linux sort ignoring zeros | E-mail me updates | Report abuse Register or log in to remove Ijack Linux Expert July 2, 2010 4:36:13 PM I'm not quite sure what your input file looks like. It certainly seems to work OK if the dates are the first item on each line and are in the format: yyyymmdd which is what you need for a sort to work. Could you give us an example? | Report abuse Anonymous July 3, 2010 12:12:30 PM Hi.. well the lines in the log start with 30-06-10_blah blah blah 31-06-10_blah etc 01-07-10_blah blah <---- this is the culprit because this is put at the bottom of the log file, where as I want the latest to be always at the top. with sort -rn | Report abuse skittle Linux Expert July 3, 2010 5:55:51 PM The problem is with the parser. It doesnt work the way you want it to, though it is working correctly! 01<30<31 The easier solution to this is to change your date format: yy-mm-dd will fix it, or else you will need to write your own parser, or do a for loop or something else creative. | Report abuse Ijack Linux Expert July 3, 2010 6:01:40 PM Sort isn't going to work in the manner you are using it with that input. 10710 is less than 310610, so it is sorting correctly. You need to be a bit more creative. What about: sort -rn -t '-' -k 3 -k2 -k1 i.e. divide the number into 3 fields separated by "-" then reverse sort on the 3rd, 2nd and 1st fields (in that order). | Report abuse Register or log in to remove Ask the community Publish Tom's Hardware>Forum>Linux/Free BSD>Linux sort ignoring zeros> Related ressources: ForumWindows Explorer Sort by filename sorts wrong ForumLinux crashing, BIOS not loadings ForumTrouble Accessing Files on HDD using IDE/SATA to USB adapter ForumAdvice on Linux Build That Will Last Me 10 Years - UPDATED!!! ForumGeForce And Radeon Take On Linux ForumAn Open Letter To The Linux Enthusiasts. ForumWhich linux distro on new ASUS 1215N? ForumHard wear guy needs help choosing which linux to use. ForumWhy I Use Linux and not Windows XP. ForumAdvice on Linux Build That Will Last Me 10 Years ForumHORRIBLE experience with Newegg ForumAny advice for a sort of "noob" EQ player thinking of play.. ForumGames sort of like Elite Forumweird asymmetric PAUSE autoconfiguration code ? ForumMicrosoft promoted from " Sort of Evil" to "Evil" ForumXP Won't Boot WIth Large Hard Drive ForumBoot Problems ForumQuickbook files compatible between windows xp and linux ForumLinux change nikon NEF files to JPG Forum[Solved] Unable to Connect to the Internet in Linux More resources !