Talk About Network



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: Inserting f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 2198 of 2236
Post > Topic >>

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.




 7 Posts in Topic:
Inserting fields by reading and comparing two files? -->
google@[EMAIL PROTECTED]   2008-03-20 15:23:36 
Re: Inserting fields by reading and comparing two files? -->
Ed Morton <morton@[EMA  2008-03-20 17:30:40 
Re: Inserting fields by reading and comparing two files? -->
Grant <g_r_a_n_t_@[EMA  2008-03-21 09:55:45 
Re: Inserting fields by reading and comparing two files? -->
Ed Morton <morton@[EMA  2008-03-20 23:27:59 
Re: Inserting fields by reading and comparing two files? -->
Gecko12332 <google@[EM  2008-03-20 18:17:53 
Re: Inserting fields by reading and comparing two files? -->
Ed Morton <morton@[EMA  2008-03-20 21:39:45 
Re: Inserting fields by reading and comparing two files? -->
Ed Morton <morton@[EMA  2008-03-20 21:51:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat May 17 0:54:43 CDT 2008.