Input File:-
COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 SMS Email AO Mail Post N Cell
VEGE Potato E W 396 12 0 384 0 0 0 0 0
VEGE Onion S W 17 0 17 0 0 0 0 0 0
FRUIT APPLE N W 549 61 0 0 0 0 0 488 0
FRUIT APPLE SE W 291 14 239 38 0 10 0 0 0
FRUIT APPLE EAMS W 397 32 309 56 309 309 0 0 0
FRUIT APPLE SEA W 808 58 663 87 488 20 0 0 0
The value in Column 3 should determine that among columns $7(SMS),$8(EMAIL),$9(AO),$10(Mail),$11(P),$12(N) and $13(cell), which column will have a non-zero integer value and which will have value zero.
eg.
example 1- if column 3 has value E then code should check only column 7,9,10,11,12,13 and sum of these columns (7+9+10+11+12+13) should be zero . If it is Zero then add GOOD else add WARNING to Newcolumn.
like in row 1 in the above file the sum of the 7,9,10,11,12,13 columns is zero so added Good in the out put file.
example 2 -if Column 3 has value SE then code should only check columns 9,10,11,12,13 and sum of these columns (9+10+11+12+13) should be zero.If it is Zero then add GOOD else add WARNING to Newcolumn.
like in row 4 the sum of columns 9,10,11,12,13 is not zero so added warning to the output file.
Now, single character value like E, S, A etc is fine but when there is a string like SE or AM or EAMS then there is a problem.
Like row 5 column 3 has values EAMS so it should only check column 11,12,13 and if those columns are greater then zero then add WARNING to Newcolumn.
Column 3 can be combination of any predefined values in no particular sequence eg. EM,ES,E,S,M,EAMS,EMAS,EP,P,SEC,SEA and more.
Conditions based on which code will decide GOOD or WARNING:-
if Column 3 has value= E then check column 7,9,10,11,12,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= S then check column 8,9,10,11,12,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= A then check column 7,8,10,11,12,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= M then check column 7,8,9,11,12,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= P then check column 7,8,9,10,12,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= N then check column 7,8,9,10,11,13 (values should be zero in each) and hence sum of these columns should be zero.
if Column 3 has value= C then check column 7,8,9,10,11,12 (values should be zero in each) and hence sum of these columns should be zero.
I know its is very confusing. Please help. For single values(can be E or ES or EAM or ...) i am using below code. I have taken E as an example.
awk 'BEGIN{FS=OFS="\t"} NR<2{print $0,"NewColumn";next} {(($3 == "E") && ((($7+$9+$10+$11+$12+$13) >0))) ?c="WARNING"$14:c="GOOD"$14;printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,c;}' Input_File
Desired OUTPUT
COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 SMS Email AO Mail Post N Cell Newcolumn
VEGE Potato E W 396 12 0 384 0 0 0 0 0 GOOD
VEGE Onion S W 17 0 17 0 0 0 0 0 0 GOOD
FRUIT APPLE N W 549 61 0 0 0 0 0 488 0 GOOD
FRUIT APPLE SE W 291 14 239 38 0 10 0 0 0 WARNING
FRUIT APPLE EAMS W 397 32 309 56 309 309 0 0 0 GOOD
FRUIT APPLE SEA W 808 58 663 87 488 20 0 0 0 WARNING