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: Process two...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 10 Topic 2151 of 2317
Post > Topic >>

Re: Process two files simultaneously

by Combatwombat <combatwombat@[EMAIL PROTECTED] > Feb 8, 2008 at 09:53 AM

Janis Papanagnou wrote:
> Ed Morton wrote:
>>
>> On 2/7/2008 1:45 AM, Combatwombat wrote:
>>
>>> Thanks for your reply, Ed!
>>
>>
>> You're welcome, but in future please leave enough context so your post 
>> stands
>> alone as this is netnews not a web forum.
>>
>>
>>> The old.csv has numerous lines like this:
>>>
>>> AAA80008    Automobile fins        AAA    CS    0
>>>
>>>
>>> the replacement csv has lines like this:
>>> AAA     Archies Automobiles and Airplanes
>>>
>>>
>>> so by replacing the AAA in the record of old.csv we end up with:
>>>
>>>
>>> AAA80008    Automobile fins        Archies Automobiles and 
>>> Airplanes    CS    0
>>>
>>> Thanks!
>>
>>
>> If those are tabs between the fields then all you need is:
>>
>> awk 'BEGIN{FS=OFS="\t"} NR==FNR{a[$1]=$2;next} {$3=a[$3];print}' 
>> replacement.csv
>> old.csv
>>
>>     Ed.
>>
> 
> It seems to fit for the OP, but mind that  {$3=a[$3];print}  will
> _always_ replace $3, even in cases where there's no substitute for
> the third field defined in the map; in that case the third field
> would be blanked.
> 
> Janis

Yes, you are right Janis.
I soon discovered that, and reworked the orginal code I had using getline:

BEGIN  { FS = ":" };{

if($10 =="y"||$10=="Y"){ # begin process of extraction because ALLOWSELL=y
qty=$6+$8;
if (($37 =="N"||$37=="n")&&qty<=0){
status=9
}else{ status=1;
}

{
#Reassign Globals
NewNR=NR; NewFNR=FNR
for (i=1; i<=37; i++){
store[i]=$i

	}#end for loop of storing data
while ((getline < "replacement.csv") > 0)# load replacements file
      if ($1==store[4]){ manf=$2 } #select the replacement
close("replacement.csv") #close replacement file

NR=NewNR; FNR=NewFNR
for (i=1; i<=37; i++){
$i=store[i]

}#end for loop of restoring data
$4=manf #assign the replacement


print 
$1,":",$1".jpg",":",$1,":",$4,":",$2,":","url",":",$7,":",$7,":",qty,":",$5,":",status,"EOREOR";

}
}


}

I'm betting this could probably be cleaned up code-wise, but it is easy 
to read and debug at the moment.

The entire project works well at converting an aging DBF based 
accounting system data into data usable by Zencart. If anyone is 
interested I will be posting my findings at 
http://combatwombat.7doves.com
soon.

Thanks for your help everyone!
 




 10 Posts in Topic:
Process two files simultaneously
Combatwombat <combatwo  2008-02-07 15:35:34 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 00:45:51 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-07 20:45:48 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 08:01:22 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-08 03:46:46 
Re: Process two files simultaneously
Janis Papanagnou <Jani  2008-02-07 19:35:34 
Re: Process two files simultaneously
Combatwombat <combatwo  2008-02-08 09:53:59 
Re: Process two files simultaneously
Ed Morton <morton@[EMA  2008-02-07 14:59:43 
Re: Process two files simultaneously
"Luuk" <luuk  2008-02-07 10:27:08 
Re: Process two files simultaneously
Janis <janis_papanagno  2008-02-07 04:44:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Fri Jul 25 20:27:39 CDT 2008.