in reply to Re^2: Compare fields in a file
in thread Compare fields in a file
Update: This code needs to be adapted if the input file contains data for more than one day.
use strict; use warnings; my %mags; while (<DATA>) { next if /X/; chomp; my $pair = (split)[-1]; my ($time, $mag) = split /,/, $pair; $time =~ s/\..*//; $mags{$time}{$mag} = $_; } for my $time (sort keys %mags) { my $mag = (sort {$b <=> $a} keys %{ $mags{$time} })[0]; print "$mags{$time}{$mag}\n"; } __DATA__ X,Y,Z,Time,Amplitude 2550,531,66,10-12-2007 07:03:08.069,2 2549,529,62,10-12-2007 07:03:08.151,1 2550,531,66,10-12-2007 07:03:09.069,1 2549,529,62,10-12-2007 07:03:09.151,2
This prints:
2550,531,66,10-12-2007 07:03:08.069,2 2549,529,62,10-12-2007 07:03:09.151,2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Compare fields in a file
by CountZero (Bishop) on Feb 10, 2009 at 20:29 UTC | |
by toolic (Bishop) on Feb 10, 2009 at 20:43 UTC |