I have two files. File A contains 2 columns (tab separated) and File B contains 1 column.
ex. File A
name1 xxxxx
name2 yyyyy
name3 zzzzz
name4 aaaaa
name5 bbbbb
File B
name3
name5
name1
What I'd like to get in an output file is:
zzzzz
bbbbb
xxxxx
I am a novice at perl and have been trying to modify the following script (designed to count the number of occurrences) to meet my needs with no success. Could someone suggest how to modify this script? Thanks for any help you can give!
unless (@ARGV == 3) { print "Use as follows: perl program.pl in1.file in2.file output.fi +le\n"; die; } my $in1 = $ARGV[0]; my $in2 = $ARGV[1]; my $fout = $ARGV[2]; open ONE, $in1; open TWO, $in2; open foutname, ">$fout"; my %hash1; my @hit; while (<ONE>){ chomp; my @hit = split(/\t/, $_); #start them as "0" for "no duplicates" $hash1{$hit[0]}=0; } close ONE; my @col; while (<TWO>){ chomp; my @col = split(/\t/, $_); #increment the counter if %hash1 has what we're looking for. ++$hash1{$col[0]} if(exists($hash1{$col[0]})); } my @dups = grep { $hash1{$_} > 0 } keys %hash1; for my $k (@dups) { print foutname "$k\t$hash1{$k}\n"; } close TWO; close foutname;
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |