Perl Format the Output in table,by removing duplicate entries

Discussion in 'Perl Misc' started by ppnair, Oct 11, 2012.

  1. ppnair

    ppnair

    Joined:
    Oct 11, 2012
    Messages:
    1
    I have written a perl code for processing file 'Output.txt' which has below Content.

    new.example.com 28
    new.example.com 28
    example.com 28
    example.com 29
    example.com 29
    example.com 29
    example.com 29
    orginal.com 28
    orginal.com 29
    orginal.com 30
    orginal.com 31
    expand.com 31
    And file 'domain.txt' has list of domain Names which i need to match against File 'Output.txt'

    new.example.com
    example.com
    orginal.com
    test.com
    new.com

    I could manage to write PERL code like this

    #!/usr/bin/perl
    use strict;
    open(LOGFILE,"Output.txt") or die("Could not open log file.");
    my $domain_name = 'domain.txt' ;
    open(DOM, $domain_name);
    my @r_contents = <LOGFILE>;
    close(LOGFILE);
    while(<DOM>) {
    chomp;
    my $line = $_;
    my @lowercase = map { lc } @r_contents;
    my @grepNames = grep /^$line/, @lowercase;
    foreach (@grepNames) {
    if ( grep /^$line/, @lowercase ) {
    $domains{lc($_)}++ ; }
    }
    }

    close(DOM) ;
    foreach my $domain (sort keys %domains) {
    my %seen ;
    ($Dname, $WeekNum) = split(/\s+/, $domain);
    my @array1 = grep { ! $seen{ $_ }++ } $WeekNum;
    push @array2, @array1;
    my @array4 = "$domains{$domain} $domain" ;
    push @matrix,@array4 ;
    }
    printf "%-10s %-25s %-25s\n", 'DoaminName', "Week $array2[0]" ,"Week $array2[1]","Week $array2[2]";
    print " @matrix \n";

    current Output looks like this.

    DoaminName Week 28 week29 week30 week 31
    2 new.example.com 35
    1 example.com 28
    4 example.com 29
    1 orginal.com 28
    1 orginal.com 29
    1 orginal.com 30
    1 orginal.com 31

    But i trying re-write the perl code to print the output like this .Please help me to correct the code.

    Domain/WeekNumber Week28 Week29 Week30 Week31
    new.example.com 2 No No No
    example.com 1 4 NO NO
    orginal.com 1 1 1 1
     
    Last edited: Oct 11, 2012
    ppnair, Oct 11, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sri2097
    Replies:
    4
    Views:
    586
    sri2097
    Jan 10, 2006
  2. gaikokujinkyofusho@gmail.com

    Removing duplicate entries/stories from a RSS feed?

    gaikokujinkyofusho@gmail.com, Dec 6, 2006, in forum: HTML
    Replies:
    2
    Views:
    561
    Andy Dingley
    Dec 6, 2006
  3. gaikokujinkyofusho@gmail.com

    Removing duplicate entries/stories from a RSS feed?

    gaikokujinkyofusho@gmail.com, Dec 6, 2006, in forum: XML
    Replies:
    1
    Views:
    466
    Paul Lutus
    Dec 6, 2006
  4. Amit
    Replies:
    3
    Views:
    424
    Richard Herring
    Sep 5, 2005
  5. Don Bruder
    Replies:
    3
    Views:
    1,001
    spikeysnack
    Aug 3, 2010
Loading...

Share This Page