in reply to Re^10: find common data in multiple files
in thread find common data in multiple files
Using @push does not maintain the correct column alignment. You need to assign values to the element associated with that file number.
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}[$i] = $value; } close $fh; } # output print join ("\t", 'ID', @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^12: find common data in multiple files
by mao9856 (Sexton) on Jan 09, 2018 at 09:12 UTC |