On Thu, 18 Jul 2002, Apolinaras Sinkevicius wrote: > I need to sort my log file cronologically what do I > need to enter in command line for SORT on RedHat to > get the log file sorted? > > Here is a snipet of log file. NOTE: this is custom > style, not the regular apache log file. > > > dialup-dialup-63.214.107.155.Dial1.Boston1.Level3.net.dial1.boston1.level3.net > [03/Mar/2002:09:40:39 -0600] "GET > /cleavers/windowsmedia_white.gif HTTP/1.1" 200 1861 > "http://www.carmelformusic.com/cleavers/themusic.html" > "Mozilla/4.0 (compatible; MSIE 5.01; Windows 95; > SPINWAY.COM)"
To start with, I will assume this is all on one line. Otherwise give up now. Secondly, no trivial solution is possible, because that date format is not sortable, since it is in reverse significance order, and the month is a name. What I would do is write a perl filter to add a beginning column with a sortable date, then strip that column after the sort. cat access_log | \ perl -e '$mn{"Jan"}=1; $mn{"Feb"}=2; $mn{"mar"}=3; $mn{"Apr"}=4; $mn{"May"}=5; $mn{"Jun"}=6; $mn{"Jul"}=7; $mn{"Aug"}=8; $mn{"Sep"}=9; $mn{"Oct"}=10; $mn{"Nov"}=11; $mn{"Dec"}=12; while(<>) { $_ =~ m!\[(\d\d)/(\w\w\w)/(\d\d\d\d):(\d\d):(\d\d):(\d\d)!; print($3.$mn{$2}.$1.$4.$5.$6."\t$_\n"); }' | sort | cut -f 2 > access_log_sorted As an added bonus if you act now, this should work with almost any log format with the date in that order. ------------------------------------------------------------------- DDDD David Kramer http://thekramers.net DK KD DKK D The plural of anecdote is not data. DK KD DDDD _______________________________________________ Redhat-list mailing list [EMAIL PROTECTED] https://listman.redhat.com/mailman/listinfo/redhat-list