jeudi 27 juillet 2017

Generate a new file based on a condition + column matching of two files

I'm trying to create a a third file based on several conditions.

I have two input files

file1 (tab separated):-

X_ID1 y_id11 num1
X_ID2 y_id31 num2  
X_ID3 y_id34 num3 
X_ID4 y_id23 num4
X_ID5 y_id2  num5 
...  
...  

file 2:-

BIOTIC AND ABIOTIC STRESS
x_id2
REGULATION OF TRANSCRIPTION
x_id1
x_id4
HORMONES
x_id5
REGULATION
x_id6
x_id13
...
...

****Please note that column 1 of file 1 is UPPERCASE and data in file2 is lowercase

What I want is so have an output file (file3) as following:-

BIOTIC AND ABIOTIC STRESS
y_id31
REGULATION OF TRANSCRIPTION
y_id11
y_id23
HORMONES
y_id2
...
...

Basically if I think of a "pseudo code" it goes as following:-

while read $line from file1; do
 if [[line1 != x_*]]; then
    print $line
 else
    match $line (case insensitively) with column 1 of file2 and print respective column2 of file2
 fi
done 

Would you please be able to help me solve this problem?

Thanks a lot in advance!

Aucun commentaire:

Enregistrer un commentaire