by "Anton Treuenfels" <atreuenfels@[EMAIL PROTECTED]
>
Jan 18, 2008 at 08:02 PM
"Ed Morton" <morton@[EMAIL PROTECTED]
> wrote in message
news:4790DBE5.2030904@[EMAIL PROTECTED]
> awk 'NR==FNR{file1[$2]=$0; next} {file2[$2]=$0}
> END {
> print "File1"
> for (key in file1)
> if (!(key in file2))
> print file1[key]
>
> print "File2"
> for (key in file2)
> if (!(key in file1))
> print file2[key]
> }' file1 file2
It is not stated by the OP but there seems to be a tacit assumption that
$2
is unique in each file, else further occurances will overwrite each other.
Assuming they ARE unique:
NR == FNR { file1[$2] = $0; next } # I stole this :)
$2 in file1 { delete(file1[$2]); next }
{ file2[$2] = $0 }
END {
print "File 1"
for ( i in file1 )
print file1[i]
print "File 2"
for ( i in file2 )
print file2[i]
}
- Anton Treuenfels