Lists
Eugene Tsyrklevich
eugene at securityarchitects.com
Thu May 25 21:33:32 CDT 2000
~sdpm~
if your logs are sorted by date and you just want to extract the last 3 lines you can do smth like:
@ARGV = '/path/to/logfile';
undef $/;
for ((split /\n/, <>)[-3..-1]) {
my ($Date, $Time, $Host, $ftpput, $ftpget, $pingloss, $pingavg)
= split;
print "$Date $Time $Host yadda yadda\n";
}
the above code is very memory inefficient so it might not work well for big log files.
check out this webpages:
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlsyn.html
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfunc/split.html
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfunc/sort.html
finally here is an excellent paper on sorting:
http://www.perl.com/CPAN-local/doc/FMTEYEWTK/sort.html
cheers.
On Thu, May 25, 2000 at 06:11:29PM -0700, Steve Meier wrote:
>
> Hey all,
>
> Could anyone tell me what the easiest way to sort through this list
> would be. What I have is a log file that looks like this:
>
> 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
>
> So for instance, I want to select the most current lines (the last
> three).
>
> Split them into there respective variables $Date $Time $Host $ftpput
> $ftpget $pingloss $pingavg
>
> Then loop them through a table to display the results on a webpage.
>
> Thanks for your help,
>
> Steve
Content-Description: Card for Steve Meier
~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