in reply to Aggregation of Similar Lines
I'd like to divide Field2 by the number of times Field1 appears.Not sure what you mean by "divide by". I'm guessing what you really mean is you'd like the resulting file to have only unique values in field2, i.e. eliminate any repetition in field2. If so, that's certainly easy enough to do. Here's one way. Note that here I'm simply ignoring the value of field1 for the purposes of determining row uniqueness.
That is, if we haven't seen this line before (ignoring the first field, as I said), then print it on through. You can do something else with the line, if printing isn't appropriate.my %seen; while (<>) { my $key = $_; $key =~ s/^\S+\s+//; # eliminate first field unless ( $seen{$key}++ ) { print; } }
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|