Just for the record, one more alternative with AWK without the need to double read the file . Seems to work even with unsorted file or even with entries found only once in the file.
$ awk '( a[$1] && (($2!=a[$1]) || ($1 in bad)) ) {bad[$1]++}; \ {a[$1]=$2;f1[FNR]=$1;f2[FNR]=$2}; \ END {for (i in f1) {if (!(f1[i] in bad)) print i,f1[i],f2[i]}}' ./tmp/file12 1 A T 2 A T 3 A T 12 C F 13 C F 21 E F
In where file12 is like:
$ cat -n ./tmp/file12 1 A T 2 A T 3 A T 4 B T 5 B T 6 B F 7 B F 8 B T 9 B F 10 B F 11 B F 12 C F 13 C F 14 D F 15 D T 16 D F 17 D F 18 D F 19 D F 20 D F 21 E F
Some explanation:
( a[$1] && (($2!=a[$1]) || ($1 in bad)) ) {bad[$1]++}; # The first time value $1 is checked,a[$1] will return null/0 since a[$1] # has never been assigned. Thus a[$1] will be evaluated as false by # condition check and further condition check and record bad marking will be skipped. # The second time (second line) a[$1] will have a value and will be evaluated as true . # Then we check if $2 is equal to previous a[$1]=$2. If it is equal all ok. # Otherwise if current $2 <> previous a[$1] $2value, mark this record as bad. # Finally there is a last check if record has been already been marked as bad. {a[$1]=$2;f1[FNR]=$1;f2[FNR]=$2}; #some array delcaration END {for (i in f1) {if (!(f1[i] in bad)) print i,f1[i],f2[i]}}' ./tmp/file12 # Printing the lines of file that does not belong in bad boys.