Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: fi
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 8 Topic 2135 of 2345
Post > Topic >>

Re: fi

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
 




 8 Posts in Topic:
fi
Madhur <madhurrajn@[EM  2008-01-18 01:23:44 
Re: fi
"Luuk" <luuk  2008-01-18 14:37:15 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 08:19:20 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 08:48:30 
Re: fi
"Luuk" <luuk  2008-01-18 16:25:33 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 11:03:33 
Re: fi
"Anton Treuenfels&qu  2008-01-18 20:02:49 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 23:23:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:50:37 CDT 2008.