in reply to Re^4: Adding object identifiers corresponding to each IP and printing them to O/P File.
in thread Adding object identifiers corresponding to each IP and printing them to O/P File.

records.pl:
#!/usr/bin/perl use strict; use warnings; my (@objects, @sets, @unsorted_records, @headers, %have_header, $resul +ts); foreach my $file (sort glob("./records*.dat")) { open(my $fh, '<', $file) or die "$file: $!\n"; my @items = <$fh>; close($fh); push @sets, \@items; } my $i = 0; foreach my $set (@sets) { foreach my $record (@$set) { next if $record =~ /^#/; chomp($record); my @ids = split m!\|!, $record; shift @ids; if (@ids > 3) { $have_header{$record}++; push @headers, $record if $have_header{$record} >= 2; } next unless @ids == 3; $objects[$i]->{$ids[0]}{$ids[1]} = $ids[2]; } $i++; } for (my $i = 0; $i < @objects; $i++) { foreach my $record (keys %{$objects[$i]}) { foreach my $item (keys %{$objects[$i]->{$record}}) { $results->{$record}{$item} += $objects[$i]->{$record}{$ite +m}; } } } foreach my $record (keys %$results) { foreach my $item (sort { $a <=> $b } keys %{$results->{$record}}) +{ my $new_record = "|$record|$item|$results->{$record}{$item}"; push @unsorted_records, $new_record; } } my @sorted_records = sort { (split m!\|!, $a)[2] <=> (split m!\|!, $b) +[2] } @unsorted_records; local $" = "\n"; print "@headers", @headers ? "\n" : ''; print "@sorted_records", @sorted_records ? "\n" : '';
records1.dat:
#LOGNUM|1|OPERATIONAL |O%:CCLN-1-CBS1 |8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6 |7|1|1553 |7|2|13 |7|3|1870 |5|4|0 |7|5|22087238 |7|6|73162814
records2.dat:
#LOGNUM|1|OPERATIONAL |O%:CCLN-1-CBS1 |8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6 |7|1|1545 |7|2|14 |7|3|1981 |5|4|0 |7|5|18613745 |7|6|81837527
__OUTPUT__
|8.2.0.4352.1.1|8.2.0.4352.1.1|0x3|14|6|3|97.232.1.2|6 |7|1|3098 |7|2|27 |7|3|3851 |5|4|0 |7|5|40700983 |7|6|155000341
  • Comment on Re^5: Adding object identifiers corresponding to each IP and printing them to O/P File.
  • Select or Download Code

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.