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
poj#!/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"; } }
|
|---|
| 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 |