in reply to Re^7: find common data in multiple files
in thread find common data in multiple files
Hi BR
Thank you for your time and patience. As you suggested i tried to match two files (4_os_10.txt and 4_os_11.txt) and I got desired output that is common data with your code and also with the code provided by BillKSmith. I tried it for more that 3 files .txt pair and found that maybe there isn't anything common among all 25 files.
I found that matched data exist only in 18 files out of 25 when i used following code. Please correct me if i get it wrong. It prints matched first column with common ID (say ID121) among all 25 files and then print second name only if it exists in file. Thus output I get files column all IDs and second column of each of 25 .txt files.
#!/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"; } } $ code.pl *.txt
Please suggest me if this code can give me desired output. Regards mao9856
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: find common data in multiple files
by thanos1983 (Parson) on Jan 08, 2018 at 11:06 UTC | |
by mao9856 (Sexton) on Jan 09, 2018 at 05:49 UTC | |
by poj (Abbot) on Jan 09, 2018 at 07:39 UTC | |
by mao9856 (Sexton) on Jan 09, 2018 at 09:12 UTC |