[SOLVED] sorting files with abnormal date structure
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I have a directory that contains about 200 files that need to be sorted into chronological order.
The problem is, all the files were retrieved on the same day, so I have to use the weird dates that are in the file names.
The files are 'dated' using the weird American convention of putting the month name first followed by the day and ending with the year.
Any suggestions on how to get them to list in chronological order? Or at least to bulk rename them with a sane, sortable, date?
The sort command features sorting by month name (-M option) as well as setting up several sort keys (-k). Then there is the question how the sort fields are defined - by character position or by delimiters like white space and commas.
The American system of MM/DD/YYYY is weird, but even the more "standard" system of DD/MM/YYYY wouldn't make it any easier to sort. The system to use for file navigation is YYYYMMDD, but nobody uses that in normal life (though anybody who's had to face this problem before definitely uses it in their file naming conventions!).
If it were me, I would just write a script to rip out the date from the filename and rename it to YYYYMMDD.
Thanks everyone for the responses.
However, it looks like I'm going to have to do some manual work as some of the files have different formats.
The only consistent part is that the months are written in words!
I'm marking this thread as 'solved' since there really is no practical solution other than to go through the list and renaming each file to a more sane result.
Last edited by qlue; 10-30-2015 at 01:09 PM.
Reason: final words.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.