printing lines where certain columns do not match, with awk

user2232814 picture user2232814 · Apr 26, 2013 · Viewed 14.3k times · Source

I have a tab separated file like this:

1       10502   C       T  
1       10506   C       T  
1       10567   G       A 
...

And I'm trying to print out all lines where column 3 != column 4, excluding the cases where column 3 = C and column 4 = T.

I tried

awk '{
if (($3 == $4) || ($3 == C && $4 == T) )
        next ;
else
        print $0; }'

but I'm not sure what's going wrong...

Answer

Kent picture Kent · Apr 26, 2013

just fix your codes:

awk '($3 != $4) && !($3=="C" && $4=="T")' file