Hi I have 25 files containing two columns in each file. I want to find and print common (ID and name for example ID121 ABC14) data present in in each of 25 files
File 1 ID121 ABC14 ID122 EFG87 ID145 XYZ43 ID157 TSR11 ID181 ABC31 ID962 YTS27 ID567 POH70 ID921 BAMD80 File 2 ID111 RET61 ID157 TSR11 ID181 ABC31 ID962 YTS27 ID452 FYU098 ID121 ABC14 ID122 EFG87 File 3 ID121 ABC14 ID612 FLOW12 ID122 EFG87 ID745 KIDP36 ID145 XYZ43 ID157 TSR11 ......... File 25 ID122 EFG87 ID809 EYE24 ID157 TSR11 ID921 BAMD80 ID389 TOP30 ID121 ABC14 Output: ID121 ABC14 ID122 EFG87 ID157 TSR11
All these files are .txt files so i want to compare all 25 files and print data that exists in all 25 files. Please help.
#!/usr/bin/perl use strict; use warnings; my %result; my @counts=(); foreach (@ARGV) { my $column=0; open my A, "<", "@counts "could not open file1 $!"; while (<A>) { chomp; my $key = (split /\t/, $_)[0]; $result{$key} = 1; $result{$key}++; if ($result{$key} == 20 { print "Line with $key is present in all twenty \n"; } } close (A); }; foreach (@counts) { s/^\s//g; print $_,"\n"; };
In reply to find common data in multiple files by mao9856
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |