Friday, 23 August 2013

Comparing Files based on 5 fields using Awk and Bash

Comparing Files based on 5 fields using Awk and Bash

I want to compare File1 and File2 (Separated by spaces) using five fields
(Column 1,2,4,5,6).
*Logic:*If column 1 and 2 of File1 and File2 match exactly and if the
File2 has the same characters as any of the characters present in column 4
and 5 of file1 then those lines of file1 and file2 are concatenated and
redirected as output.
File1:
s2/80 20 . A T 86 N=2 F=5;U=4
s2/20 10 . G T 90 N=2 F=5;U=4
s2/90 60 . C G 30 N=2 F=5;U=4
File2:
s2/90 60 . G G 97 N=2 F=5;U=4
s2/80 20 . A A 20 N=2 F=5;U=4
s2/15 11 . A A 22 N=2 F=5;U=4
s2/90 21 . C C 82 N=2 F=5;U=4
s2/20 10 . G G 99 N=2 F=5;U=4
s2/80 10 . T G 11 N=2 F=5;U=4
s2/90 60 . G T 55 N=2 F=5;U=4
Output:
s2/80 20 . A T 86 N=2 F=5;U=4 s2/80 20 . A A 20 N=2
F=5;U=4
s2/20 10 . G T 90 N=2 F=5;U=4 s2/20 10 . G G 99 N=2
F=5;U=4
s2/90 60 . C G 30 N=2 F=5;U=4 s2/90 60 . G G 97 N=2
F=5;U=4
I'm new in this field and would appreciate any guidance.

No comments:

Post a Comment