Hi BR

I am sorry for all misunderstanding. I try to put it in a simple way. I have 25 different txt files. Each of 25 files has only two columns. One column is id (ID21) and second column is name (ABC12). Each files has different number of rows. Each row has data like (ID21 ABC12). i made it sure that one id and name (say ID21 ABC12) appears only once in one file. That means one file doesn't have any replicate values of "ID" and "name". Also there is fixed "ID" for particular "name". So I want if ID21 ABC12 is present in all 25 txt files it should be printed in output.

I am thankful for all who have provided me solutions. But i guess problem is ID21 ABC12 is not appearing in all 25 files. So, all codes provided are not working for me. And also i dont know in which of the files ID21 ABC12 is appearing. So, my last posted code was to generate output like this:

First column: print all common IDs (even if they are present in 2 files), then second column: has file 1 with name which match their id. Nothing prints if it doesn't match ID (so appear blank). Third column: is file 2 which prints name matching its id and so on.

So what I want my output to be is match all keys first then join the second column of each 25 files labelling file name (that is file1, file2 etc). I want output to be like this:

ID file1 file2 file3 file4 file5 file6......file25 ID21 ABC12 ABC12 ABC12 ABC12 ID22 XYZ11 XYZ11

this output shows ID21 and ABC12 is present in more than 2 files. And ID21 and ABC12 is present in file1, file2, file5 and file25 and absent in other files. next row has ID22 and matching name is found in file2 and file4. The following code for getting above mentioned output

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

Please let me know if this was answer for what you asked me:) Regards mao9856


In reply to Re^10: find common data in multiple files by mao9856
in thread find common data in multiple files by mao9856

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.