I have made few changes to the awk code.
Code:
awk '
BEGIN {
while ( getline < "A" ) { arr[$0]=1 }
}
{ if ( arr[$0] != 1 ) print FILENAME":" $0
else delete arr[$0];
}
END {
for( key in arr )
if ( arr[key] == 1 ) print "A:" key
} ' B
Code:
while ( getline < "A" ) { arr[$0]=1 }
Here we read line by line from file A and assign one to array with the line read from file as key ( or index ).
Code:
{ if ( arr[$0] != 1 ) print FILENAME":" $0
else delete arr[$0];
}
Here we are checking that line read from file B is present in array arr. If condition
arr[$0] != 1 is satisfied which means that line is not available in file A and print or else both the file contain this line and delete it from array arr.
Code:
END {
for( key in arr )
if ( arr[key] == 1 ) print "A:" key
}
Since we have deleted whatever is common to both files and print the remaining lines which is present only in file A.