Your date format isn't perfect for sorting, but you can pipe your file through the unix sort command using ~ as your separator, on the fourth (0, 1, 2, 3) column, ignoring blank spaces:
sort -b -t '~' +3
That's assuming your OS has a compatible 'sort'.
You can reverse it for descending order:
sort -b -r -t '~' +3
It would be better if date was in a fully sortable format like yyyymmdd, as referenced above, or even yy/mm/dd
How about this mess:
cat <log file> | \
perl -p -e 's|(\d\d)/(\d\d)/(\d\d)|$3/$1/$2|' | \
sort -r -b -t '~' +3 | \
perl -p -e 's|(\d\d)/(\d\d)/(\d\d)|$2/$3/$1|'
Note: You can do a lot on the command-line, but it's not always the best way to do things.
If you want to parse a few decades of historical data and aren't worried about your script being around in 50 years or so, you can go way overboard:
cat <log file> | \
perl -p -e 's|(\d\d)/(\d\d)/(\d\d)|($3 > 50 ? "19$3" : "20$3")."$1$2"|e' | \
sort -r -b -t '~' +3 | \
perl -p -e 's|(\d\d)(\d\d)(\d\d)(\d\d)|$3/$4/$2|'
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.