I have a file of multiple columns. I would like to make an additional column based on the values of 2 columns from this file.Example input:A B C D E F1 2 T TACA A 3 23 4 I R 8 29 3 A C 9 3If the values in cols 3 and 4 (labelled C and D) are the letters A,C,G or T, col 7 should be P.If the letters in cols 3 and 4 are I, D, or R, col 7 should be Q.If there are multiple letters in either column 3 or 4, col 7 should be Q.Desired ouput:A B C D E F G1 2 T TACA A 3 2 Q3 4 I R 8 2 Q9 3 A C 9 3 PI have the following code except this replaces some of the col 3 values with '1'. I want to leave cols 1-6 unchanged.awk '{if ((($3!=A && $3!=C && $3!=G && $3!=T) || ($3=I || $3=D || $3=R)) || (($4!=A && $4!=C && $4!=G && $4!=T) || ($4=I || $4=D || $4=R))) { $7 = INDEL } else { $7 = SNP }}1' filename > newfilename
How to add new column, where the value is based on existing columns with awk
bash;text processing;awk
This works with mawk:awk 'NR==1{$7=G;print;next} \  $3~/^[A,C,G,T]$/ || $4~/^[A,C,G,T]$/ {$7=P} \  $3~/^[I,D,R]$/ || $4~/^[I,D,R]$/ {$7=Q} \  $4~/[A-Z][A-Z]/ || $3~/[A-Z][A-Z]/ {$7=Q} 1' fileline: In the first line write the G in the header.line: If $3 of $4 are A, C, G or T then $7 is P.line: If $3 of $4 are I, D, or R then $7 is Q.line: If $3 of $4 are more than one Letter then $7 is Q. The 1 at the end prints all lines.