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


|