in reply to Re: print first column, unique word in each row along with number times that word is repeated in each row
in thread print first column, unique word in each row along with number times that word is repeated in each row

Yes please. This was the code that got me desired output which is my new input now Re^11: find common data in multiple files by poj

  • Comment on Re^2: print first column, unique word in each row along with number times that word is repeated in each row

Replies are listed 'Best First'.
Re^3: print first column, unique word in each row along with number times that word is repeated in each row
by poj (Abbot) on Jan 11, 2018 at 06:37 UTC

    Add 2 more columns into the array and shift the others up

    #!/usr/bin/env perl use strict; use warnings; my %data = (); #@ARGV = map { "File$_" }(1..4); my $num = @ARGV; # input for my $i (0..$num-1){ open my $fh,'<',$ARGV[$i] or die "$!"; while (<$fh>) { my ( $key, $value ) = split; $data{$key}[0] = $value; $data{$key}[1] += 1; # count $data{$key}[$i+2] = $value; } close $fh; } # output print join ("\t", 'ID', 'Name','Count', @ARGV),"\n"; foreach my $key ( sort keys %data ) { my @line = map { $_ || '-' } @{ $data{$key} }[0..$num+1]; if (grep $_ eq '-',@line){ print join ("\t", $key, @line),"\n"; } }
    poj

      Hi poj

      When I tried your code it gives output 1 in all rows. Also number of rows are reduced. IDs are printing though (first column) but rows have reduced. And it also prints "-" in second and fourth column.

      I am trying to this code for the output (now my new input) you coded earlier Re^11: find common data in multiple files

      Regards mao9856