Need to delete all lines where any line meets a condition

Here is an example of a file...

foo1,good
foo1,good
foo2,error
foo2,good

Note that both rows for foo1 have good in the 2nd field, but one of the foo2 rows has error...

I need something in ksh/awk/perl that will delete ALL foo2 lines if ANY of them have error in the 2nd field...so:

foo1,good
foo1,good
foo2,error
foo2,good

becomes:

foo1,good
foo1,good

Please help...I know it should be simple, but I can't figure it out.

Thanks!

try this...

grep -v $(awk -F, '$2 ~ /error/{print $1}' file1) file1
{ grep -q "foo2,error" file1 && grep -v "foo2," file1 ; } || cat file1

awk version:

awk -F, '$2=="error"{F[$1]} FNR!=NR && !($1 in F)' infile infile

(the input file is specified twice)

Sorry for the late replies...I've been trying to figure this out as much as possible myself and I'm just plain stuck...

This gives me
awk: syntax error near line 1
awk: bailing out near line 1

My flavor of Unix doesn't support grep -q

This simply displays my file as is and doesn't make any changes.

it can't write to file. you need to redirect it.

grep .... file > temp 
mv temp file

also try with nawk

try:

awk -F, '
{
 a[NR]=$0;
 if ($0 ~ /foo2.*error/) e=$1;
}
END {
 for (i=1; i<=NR; i++) {
   if (!e) {
     print a[1];
   } else {
     if (a !~ e) print a;
   }
 }
}
' file1

On Solaris use /usr/xpg4/bin/awk or nawk rather than awk