in reply to Sort on Number Embedded in String

Please, besides fixing this immediate problem, please fix your archive filename scheme. Dates in formats like "3Mar2005" are really VERY unhelpful. You can't sort them without lots of extra processing.

Pick the ISO 8601 Standard Date Format for any dates that must be human-readable and machine-readable. It reduces language problems (what is "September" in French?), and cultural problems (is "01/06/05" in January or June?).

Example: 2005-03-21.fwlog.gz

(You can put the date first, or the filename first, but I prefer date-first so that multiple filenames related to a given date will naturally sort together.)

Then all these things will sort properly. They will sort at the command line, they will sort in your GUI file managers, they will sort in your perl code, all without expensive and error-prone coding.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re^2: Sort on Number Embedded in String
by grinder (Bishop) on Mar 23, 2005 at 07:46 UTC
    please fix your archive filename scheme

    Sometimes, when dealing with proprietary software, you do not have such a luxury. In the present case, I'd bet my lunch on the fact that the OP is dealing with Checkpoint FW-1 logs. Yes, the naming scheme sucks, but I doubt filing a bug report would do anything because they would probably reply that it would breaking existing code that deals with the current scheme. Renaming them to do local processing is just a hassle. This is exactly the sort of task Perl excels at, making the difficult things easy.

    - another intruder with the mooring in the heart of the Perl