in reply to max and min values in 3-column file
Another way to do this by reading the file a line at a time:
$ echo "Column1 Column2 Column3 2870 S11 1 574 S11 2 317 S11 3 31 S11 4 1 S11 6 1 S11 7 2925 S12 1 8 S12 5 1 S12 6 1 S12 9 " | perl -e' use warnings; use strict; my ( @lowest, @highest ); while ( <> ) { next if /^\D/; my @fields = split; unless ( @lowest ) { @lowest = @highest = @fields; next; } if ( $lowest[ -1 ] >= $fields[ -1 ] && $lowest[ 0 ] < $fields[ 0 ] + ) { @lowest = @fields; } if ( $highest[ -1 ] < $fields[ -1 ] ) { @highest = @fields; } } print join( "\t", "Lowest:", @lowest ), "\n"; print join( "\t", "Highest:", @highest ), "\n"; ' Lowest: 2925 S12 1 Highest: 1 S12 9
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: max and min values in 3-column file
by perldummie (Initiate) on Feb 06, 2011 at 14:31 UTC | |
by tospo (Hermit) on Feb 07, 2011 at 09:48 UTC |