I have a problem that's giving me a bit of a headache, but it doesn't tend to take much as a relative beginner. I have a file that looks like this    ID A1 A2 A3    1  A  G  A    2  T  G  A    3  T  A  G    4  T  G  A    5  A  A  G    6  A  C  A    7  C  T  Gwhich is thousands of rows long and made up of G,C,T,A, where G complements C and A complements T.  What I'm trying to do is to search for a match for A1 in either in A2 or A3. If there is a match then for it to be left as it is and if there isn't to change A2 and A3 to their complements i.e. A=T and G=C and vice versa.So the output would be:    ID A1 A2 A3    1  A  G  A    2  T  C  T    3  T  T  C    4  T  C  T    5  A  A  G    6  A  C  A    7  C  A  CI thought I could do it by using awk to filter matching and unmatching IDs using these:   awk '{if($2 != $3 || $2 != $4) print $0}' mergedlist > nonmatchlistand   awk '{if($2 == $3 || $2 == $4) print $0}' mergedlist > matchlistbut it only worked for one variable i.e T in the former and A in the latter.Many thanks for your input.
Multiple column matching and adjusting with awk
linux;bash;text processing;awk
perl -lane 'sub flip { if ($_[0] eq T) { A } elsif ($_[0] eq A) { T } elsif ($_[0] eq G) { C } elsif ($_[0] eq C) { G } else { $_[0] } } if (!($F[1] eq $F[2] or $F[1] eq $F[3])) { $F[2] = flip($F[2]); $F[3] = flip($F[3]) } print @F' < inputShould be easy to port back to awk as it's not really doing anything fancy, but that would take me more time to figure out.