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 10 of 10 Topic 2151 of 2317
Post > Topic >>

Re: Process two files simultaneously

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Feb 7, 2008 at 04:44 AM

On 7 Feb., 08:45, Combatwombat <combatwombat@[EMAIL PROTECTED]
> wrote:
> Thanks for your reply, Ed!
>
> The old.csv has numerous lines like this:
>
> AAA80008 =A0 =A0 =A0 =A0Automobile fins =A0 =A0 =A0 =A0 AAA =A0 =A0 CS
=A0=
 =A0 =A00
>
> the replacement csv has lines like this:
> AAA =A0 =A0 Archies Automobiles and Airplanes
>
> so by replacing the AAA in the record of old.csv we end up with:
>
> AAA80008 =A0 =A0 =A0 =A0Automobile fins =A0 =A0 =A0 =A0 Archies
Automobile=
s and Airplanes =A0 =A0 =A0 CS =A0 =A0 =A00
>
> Thanks!

You would first build up a mapping table from the data in
replacement file, then process the data file and replace the
respective data...

awk '...' replacementfile datafile

Now your data files seem to have different field separators,
I suspect there's a TAB in the replacementfile and comma in
the datafile, at least in the examples of your first posting
in this thread...

  awk -v FS=3D"\t" -v OFS=3D"\t" '...'  replacementfile FS=3D"," datafile

=2E..but if you have just TABs as separators, as it *seems*
here use

  awk -v FS=3D"\t" -v OFS=3D"\t" '...' replacementfile datafile

To distinguish whether you are in the first or second file
you compare NR and FNR; in case of the first processed file
they match...

awk -v FS=3D"\t" -v OFS=3D"\t" '
     NR=3D=3DFNR { map[$1] =3D $2 ; next }
     ...
    ' replacementfile datafile

Now you replace the respective field in the data file...

awk -v FS=3D"\t" -v OFS=3D"\t"
    'NR=3D=3DFNR { map[$1] =3D $2 ; next }
     $3 in map { $3 =3D map[$3] }
     { print }
    ' replacementfile datafile


(The code is untested.)

Janis
 




 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 14:55:43 CDT 2008.