Re: Inserting fields by reading and comparing two files? -->
by Ed Morton <morton@[EMAIL PROTECTED]
>
Mar 20, 2008 at 09:51 PM
On 3/20/2008 9:39 PM, Ed Morton wrote:
>
> On 3/20/2008 8:17 PM, Gecko12332 wrote:
>
>>Wow! Grant & Ed for the amazing help ( more like the answer:) ) on
>>this! Worked like a charm! I did forget one thing which was some of
>>these names had middle initials which were always single char followed
>>by a period IE Jane S. Doe so I stripped any possible middle initials
>>out by doing the following, though it took me forever to figure out:
>>awk -F. '{gsub("\\.","");gsub(" . "," "); print $1}' names.out >
>>names_no_middle_initial.out
>
>
> You could just leave them in:
>
> awk 'NR==FNR{n=$1;$1="";sub(/ +/,"");a[n]=$0;next} {$2=a[$1]}1'
names.out FS=":"
> OFS=":" masterfile.out
Or you could've just not included them. The original script I posted was:
awk 'NR==FNR{a[$1]=$2" "$3;next}{$2=a[$1]}1' names.out FS=":" OFS=":"
masterfile.out
Just tweak it to this to skip any middle initials:
awk 'NR==FNR{a[$1]=$2" "$NF;next}{$2=a[$1]}1' names.out FS=":" OFS=":"
masterfile.out
Ed.