Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort by

Status
Not open for further replies.

AIXFinder

IS-IT--Management
Jan 4, 2007
97
US
I have this script, and I want the output sorted by

first, $date="$month/$day/$year";
and then
$otime="$hours:$minutes:$seconds";

thx much

#!/usr/bin/perl
open (PASSWD,"/etc/passwd") or die "Cannot open /etc/passwd: $!\n";
while (<PASSWD>) {
($user,undef,$uid,undef,$name,undef)=split ":";
if ($uid > 203 and $uid < 1000) {
if ($name eq "") { $name = "Unknown"; }
$last = `lsuser -a time_last_login $user`;
if ($last !~ /time_last_login/) {
$date="Unknown";
$otime="";
$time=0;
} else {
(undef,$time)=split("=",$last);
($seconds,$minutes,$hours,$day,$month,$year,undef) = localtime($time);
$month += 1;
$year += 1900;
$date="$month/$day/$year";
$otime="$hours:$minutes:$seconds";
}
write;
}
}
Authored by: ethanjohnsons
 
it looks like you alredy have the time in epoch seconds,

Code:
(undef,$time)=split("=",$last);

so all you have to do is a sort based on $time. But your script looks like it just prints as it goes through the file, so there is nothing to sort.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
mdy, not ymd ...

push your records onto a hash keyed by $date.$time, and then sort the hash by the key

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top