LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 10-30-2015, 01:50 AM   #1
qlue
Member
 
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
Question sorting files with abnormal date structure


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?
 
Old 10-30-2015, 01:56 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,848

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
that is the command rename You can specify regexp and also reorder parts...
 
Old 10-30-2015, 02:45 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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.
 
1 members found this post helpful.
Old 10-30-2015, 11:39 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
Old 10-30-2015, 11:44 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i personally like:
Quote:
[schneidz@hyper ~]$ date +%Y-%j
2015-303
 
Old 10-30-2015, 01:06 PM   #6
qlue
Member
 
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747

Original Poster
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
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.
 
  


Reply

Tags
american date, sorting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sorting of files and creating a loop to process them date wise umix Linux - Newbie 8 12-03-2011 04:12 AM
Abnormal behavior of system date jeesun Linux - Hardware 2 08-26-2009 10:32 PM
Trying to move files beyond cutoff date in subfolders and retain directory structure Erik Mesoy Linux - Newbie 2 03-16-2008 08:58 AM
Sorting all files of home folder modified after a specific date for backup fc6_user Linux - General 2 03-30-2007 02:24 AM
Sorting files by time / date. TheRealDeal Linux - General 2 08-06-2006 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration