in reply to Re^2: 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

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
  • Comment on Re^3: print first column, unique word in each row along with number times that word is repeated in each row
  • Download Code

Replies are listed 'Best First'.
Re^4: print first column, unique word in each row along with number times that word is repeated in each row
by mao9856 (Sexton) on Jan 11, 2018 at 07:11 UTC

    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