jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
The output is:#! /usr/bin/perl -lw use strict ; use warnings ; my @i ; # usern pid ? ? startt ? ? command $i[0] = "wwwrun 17275 10449 0 2006 ? 00:00:00 /usr/sb..."; $i[1] = "root 3826 1 0 Jan08 ? 00:00:00 su -" ; $i[2] = "root 3826 1 0 Jan 08 ? 00:00:00 su -" ; $i[3] = "root 3547 1 2 06:49 ? 00:11:56 zmd /us..."; $i[4] = "root 3547 1 2 06:49:12 pts/1 00:11:56 zmd /us..."; my $usern ; my $pid ; my $time ; my $command ; foreach ( @i ) { ($usern, $pid, $time, $command) = ( $_ =~ /^ (\w+) # capture username \s+ (\d+) # capture PID \s+\d+\s+\d+\s+ (?: # cluster (not capturing) (\d{4}) # capture %Y | # or (\d{2}:\d{2}) # capture %H:%M | # or (\d{2}:\d{2}:\d{2}) # capture %H:%M:%S | # or (\w{3}\d{2}) # capture %b%d | # or (\w{3}\s+\d{2}) # capture %b %d ) \s+\S+\s+\S+\s+ # skip 2 columns after the 5th column (.*) # capture the command $/gx ) ; printf "usern=%s pid=%s, time=%s command=%s\n", ($usern || ""), ($pid || ""), ($time || ""), ($command || "") ; }
I think I do something fundamentally wrong when parsing the date/time column.....usern=wwwrun pid=17275, time=2006 command= usern=root pid=3826, time= command= usern=root pid=3826, time= command= usern=root pid=3547, time= command=06:49 usern=root pid=3547, time= command=
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing variable input (perlre problem)
by davorg (Chancellor) on Mar 19, 2007 at 15:24 UTC | |
|
Re: parsing variable input (perlre problem)
by johngg (Canon) on Mar 19, 2007 at 15:33 UTC | |
|
Re: parsing variable input (perlre problem)
by Moron (Curate) on Mar 19, 2007 at 16:35 UTC | |
by davorg (Chancellor) on Mar 19, 2007 at 16:50 UTC | |
by Moron (Curate) on Mar 19, 2007 at 16:59 UTC | |
|
Re: parsing variable input (perlre problem)
by jeanluca (Deacon) on Mar 20, 2007 at 12:33 UTC | |
by davorg (Chancellor) on Mar 20, 2007 at 13:13 UTC | |
by jeanluca (Deacon) on Mar 20, 2007 at 13:40 UTC |