The stupid question is the question not asked | |
PerlMonks |
comparing 2 filesby garyboyd (Acolyte) |
on Apr 06, 2011 at 16:43 UTC ( [id://897820]=perlquestion: print w/replies, xml ) | Need Help?? |
garyboyd has asked for the wisdom of the Perl Monks concerning the following question: Hi perl monks, I am trying to compare 2 files with similar data. I want to check if any of the lines in file 1 are contained in File2 and if they aren't to print that line in File 1 (with an additional column 0) and if they are present to print the line from File 2 eg File 1: 133-1452_chromosomal_replication_initiation_protein_ 1457-2557_DNA_polymerase_III_subunit_beta_ 2579-3670_recombination_protein_F_ 3687-6104_DNA_gyrase_subunit_B_ c8268-7159_aspartate-semialdehyde_dehydrogenase_ c8692-8471_prophage_p2_ogr_protein_ File 2: c8268-7159_aspartate-semialdehyde_dehydrogenase_ 33 c8692-8471_prophage_p2_ogr_protein_ 574 1457-2557_DNA_polymerase_III_subunit_beta_ 123 Output file: 133-1452_chromosomal_replication_initiation_protein_ 0 1457-2557_DNA_polymerase_III_subunit_beta_ 123 2579-3670_recombination_protein_F_ 0 3687-6104_DNA_gyrase_subunit_B_ 0 c8268-7159_aspartate-semialdehyde_dehydrogenase_ 33 c8692-8471_prophage_p2_ogr_protein_ 574 The files are not sorted in any way, so the lines are not consecutive in either file. I have tried adapting a number of bits of code that I have found on the web, but none of these are working properly. So far I have this:
But this just print out a list of lines from the second file. Any help would be appreciated!
Back to
Seekers of Perl Wisdom
|
|