Lists
C. Abney
cabney at cyberpass.net
Fri May 26 16:59:09 CDT 2000
~sdpm~
Oh, ick. To do this correctly is complicated, I think...
On Thu, 25 May 2000, Steve Meier wrote:
> 5/25/2000 17:28:37 HostA 2250.16 2136.20 0 0
> 5/25/2000 17:28:52 HostB 905.77 928.76 0 0
> 5/25/2000 17:29:11 HostC 3632.60 3300.78 0 0
> 5/25/2000 18:28:37 HostA 2250.16 2136.20 0 0
> 5/25/2000 18:28:52 HostB 905.77 928.76 0 0
> 5/25/2000 18:29:11 HostC 3632.60 3300.78 0 0
A schwartzian transform (named after its inventor, Tom Christiansen)
is what you need.) Wish I could bang one out for you...
> So for instance, I want to select the most current lines (the last
> three).
can I just order them in descending order for date, ascending hostname,
and descending comm data?
> Split them into there respective variables $Date $Time $Host $ftpput
> $ftpget $pingloss $pingavg
sure...
> Then loop them through a table to display the results on a webpage.
#! /usr/bin/perl -w
# there must be better tweaks to this
# It's not tested code, and there's some baggage... I wish I could
# say it's a schwartzian transform, but... wtf is it??
# prolly don't need to sort on anything past the hostname...
while (<>)
{
chomp;
$line = $_;
($d,$t,$h,$p,$g,$l,$a) = split / +/,$line;
($m,$d,$y) = split '\/', $d;
($hr,$min,$s) = split ':', $t;
$m = sprintf("%02d", $m);
$d = sprintf("%02d", $d);
$y = sprintf("%04d", $y);
$t = sprintf("%02d:%02d:%02d", $hr,$min,$s);
@tmp = ($line,$m,$d,$y,$t,$h,$p,$g,$l,$a);
push @elems, [@tmp];
}
@elems = sort {
$b->[3] <=> $a->[3]
||
$b->[1] <=> $a->[1]
||
$b->[2] <=> $a->[2]
||
$b->[4] cmp $a->[4]
||
uc($a->[5]) cmp uc($b->[5])
||
$b->[6] <=> $a->[6]
||
$b->[7] <=> $a->[7]
||
$b->[8] <=> $a->[8]
||
$b->[9] <=> $a->[9]
} @elems;
print "$_->[0]\n" for (@elems);
output:
(0)[2218]$ ./1-sort_log.plx < data
5/25/2000 18:29:11 HostC 3632.60 3300.78 0 0
5/25/2000 18:28:52 HostB 905.77 928.76 0 0
5/25/2000 18:28:37 HostA 2250.16 2136.20 0 0
5/25/2000 17:29:11 HostC 3632.60 3300.78 0 0
5/25/2000 17:28:52 HostB 905.77 928.76 0 0
5/25/2000 17:28:37 HostA 2250.16 2136.20 0 0
(0)[2218]$ cat data
5/25/2000 17:28:37 HostA 2250.16 2136.20 0 0
5/25/2000 17:28:52 HostB 905.77 928.76 0 0
5/25/2000 17:29:11 HostC 3632.60 3300.78 0 0
5/25/2000 18:28:37 HostA 2250.16 2136.20 0 0
5/25/2000 18:28:52 HostB 905.77 928.76 0 0
5/25/2000 18:29:11 HostC 3632.60 3300.78 0 0
I'll let you work out the html formatting <g>
CA
--
Einstein himself said that God doesn't roll dice. But he was wrong. And
in fact, anyone who has played role-playing games knows that God
probably had to roll quite a few dice to come up with a character like
Einstein. -- Larry Wall C. Abney
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list