Compare Values between column in the same file

would it possible if code can add also "Bad" to value which is suppose to be zero but it is not.

 
 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 Bad10 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 Bad20 0 0 0 WARNING
 

like I added bad in row number 5 and 7.

Of course it would be possible. Why don't you try modifying one or more of the suggestions that have been provided to you by the volunteers who have posted solutions to your original problem to meet your new requirements. If you get stuck, show us what you have done and we'll try to help you fill in the missing pieces.

@Don ..I have tried multiple things but none of them seems working

one of those :-

 awk '
BEGIN { # Initialize skip array: S[fn] = char
# If field #3 contains the character specified by char, do NOT check
# the contents of field #fn.
S[7] = "S"
S[8] = "E"
S[9] = "A"
S[10] = "M"
S[11] = "P"
S[12] = "N"
S[13] = "C"
}
NR < 2 {# Add the requested heading field to the header line...
print $0, "Newcolumn"
# and skip to the next input line.
next
}
{ # For all other input lines, check fields 7-13 inclusive:
for(i = 7; i <= 13; i++)
# If the character corresponding to the field is not prsent in
# field #3 AND the field contains a non-zero value...
if($3 !~ S && $i)
# break out of the loop.
break
# Print the input line followed by "WARNING" if a non-zero value was
# found in a field to be checked; otherwise, print the input line
# followed by "GOOD".
{ if ($i != 0) $i="Bad"$i; print $0 },(i <= 13) ? "WARNING" : "GOOD
}' 

Guessing that you want to flag every non-ignored non-null field, try

awk '
NR == 1 {MX = split ("      SEAMPNC", CH, _)
         print $0, "NewColumn"
         next
        }
        {SUM = 0
         for (i = 7; i<=13; i++) if ($3 !~ CH)       {SUM += $i
                                                         if ($i) $i = "Bad" $i
                                                        }
         $(NF+1) = SUM?"WARNING":"GOOD"
        }
1
 ' file
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 Bad10 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 Bad20 0 0 0 WARNING
1 Like

Or, if you want a modified version of my commented script, you could try:

awk '
BEGIN {	# Initialize skip array: S[fn] = char
	# If field #3 contains the character specified by char, do NOT check
	# the contents of field #fn.
	S[7] = "S"
	S[8] = "E"
	S[9] = "A"
	S[10] = "M"
	S[11] = "P"
	S[12] = "N"
	S[13] = "C"
}
NR < 2 {# Add the requested heading field to the header line...
	print $0, "Newcolumn"
	# and skip to the next input line.
	next
}
{	# Clear warning flag.
	w = 0
	# For all other input lines, check fields 7-13 inclusive:
	for(i = 7; i <= 13; i++)
		# If the character corresponding to the field is not prsent in
		# field #3 AND the field contains a non-zero value...
		if($3 !~ S && $i) {
			# Mark the field bad and set the warning flag.
			w = 1
			$i = "Bad" $i
		}
	# Print the input line followed by "WARNING" if a non-zero value was
	# found in a field to be checked; otherwise, print the input line
	# followed by "GOOD".
	print $0, w ? "WARNING" : "GOOD"
}' file2

which, if file2 contains:

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
TREE Lemon S W 17 0 1 2 3 4 5 6 7
TREE Orange N W 17 0 10 20 30 40 50 60 70
TREE Lime NS W 17 0 100 200 300 400 500 600 700
TREE Tangerine SEAMPC W 17 0 100 200 300 400 500 600 700

produces the 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 Bad10 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 Bad20 0 0 0 WARNING
TREE Lemon S W 17 0 1 Bad2 Bad3 Bad4 Bad5 Bad6 Bad7 WARNING
TREE Orange N W 17 0 Bad10 Bad20 Bad30 Bad40 Bad50 60 Bad70 WARNING
TREE Lime NS W 17 0 100 Bad200 Bad300 Bad400 Bad500 600 Bad700 WARNING
TREE Tangerine SEAMPC W 17 0 100 200 300 400 500 Bad600 700 WARNING
1 Like

@Rudi.Thank you code worked as expected.

@Don it is adding Bad to all the values from column 7 to 13 if there is warning. I just want to add to the value which is not suppose to be zero.

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 Bad10 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 Bad20 0 0 0 WARNING

Hi Nina2910,
No, it is not.

If you look at post #25 again, you will see that it adds "Bad" to every value in columns 7 through 13 that would cause the final field to contain" WARNING" and does not modify any value in columns 7 through 13 that would not cause the final field to be set to "WARNING".

Sorry about that yes I see it now and tested it thank you so much.