in reply to Re^4: Replace table values from text database
in thread Replace table values from text database

Try this:

#! perl -sw use strict; use Inline::Files; my %reps = map{ split "\t", $_, 2 } <REPLACEMENTS>; chomp %reps; while( <DATAFILE> ) { my @items = split "\t", $_; $_ = $reps{ $_ } // $_ for @items; print join "\t", @items; } __REPLACEMENTS__ Aspergillus_clavatus_1 XP_001276684.1 pectate lyase, putative [Aspe +rgillus clavatus NRRL 1] Aspergillus_fumigatus_2 XP_001276694.1 conserved hypothetical prote +in [Aspergillus fumigatus NRRL 1] Aspergillus_flavus_3 XP_001276726.1 tyrosinase central domain prote +in [Aspergillus flavus NRRL 1] Aspergillus_terreus_4 XP_001276738.1 endoglucanase, putative [Asper +gillus terreus NRRL 1] __DATAFILE__ Aspergillus_clavatus_1 Aspergillus_flavus_198 Aspergillus_terreus_ +166 Aspergillus_fumigatus_2 Aspergillus_clavatus_1 Aspergillus_flavus_3 Aspergillus_terreus_ +4 Aspergillus_fumigatus_2 Aspergillus_clavatus_3 Aspergillus_flavus_198 Aspergillus_terreu_1 +66 Aspergillus_fumigatus_16

Output:

C:\test>1157643 XP_001276684.1 pectate lyase, putative [Aspergillus clavatus NRRL 1] + Aspergillus_flavus_198 Aspergillus_terreus_166 Aspergillus_fumigat +us_2 XP_001276684.1 pectate lyase, putative [Aspergillus clavatus NRRL 1] + Aspergillus_flavus_3 Aspergillus_terreus_4 Aspergillus_fumigat +us_2 Aspergillus_clavatus_3 Aspergillus_flavus_198 Aspergillus_terreu_166 + Aspergillus_fumigatus_16

Note:the use of Inline::Files is for testing only, you'll need to open your data files in the normal way.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.