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

In reply to Re^5: Adding object identifiers corresponding to each IP and printing them to O/P File. by shigetsu
in thread Adding object identifiers corresponding to each IP and printing them to O/P File. by Kiran Kumar K V N

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.