in reply to find common data in multiple files
Greetings to all
For printing the common data present among all 25 .txt files as input:
INPUT File1 ID121 ABC14 ID122 EFG87 ID145 XYZ43 ID157 TSR11 ID181 ABC31 ID962 YTS27 ID567 POH70 ID921 BAMD80 File2 ID111 RET61 ID157 TSR11 ID181 ABC31 ID962 YTS27 ID452 FYU098 ID122 EFG87 File3 ID121 ABC14 ID612 FLOW12 ID122 EFG87 ID745 KIDP36 ID145 XYZ43 .................. File25 ID122 EFG87 ID809 EYE24 ID921 BAMD80 ID389 TOP30 ID121 ABC14
I tried following new code:
$ code.pl *.txt#!/usr/bin/env perl use strict; use warnings; my %data; while (<>) { my ( $key, $value ) = split; push( @{ $data{$key} }, $value ); } foreach my $key ( sort keys %data ) { if ( @{ $data{$key} } >= @ARGV ) { print join( "\t", $key, @{ $data{$key} } ), "\n"; } }
it gives following output as per my understanding. Please correct me if I am wrong
OUTPUT File1 File2 File3 ...........File25 ID121 ABC14 space ABC14 ...........ABC14 ID122 EFG87 EFG87 EFG87 ...........EFG87 ID157 TSR11 TSR11 space .......... space
Thank you in advance:)
|
|---|