My question might not be quite clear... so lets get to samples datas...  

fileA  

162,400  

174,402  

175,404  

187,406 

fileB  

E-J1-N5,319319,240248,364364,**162162**  

F-J6-N1,380380,250250,360360,**162174**  

E-J6-N2,380380,240240,364374,**175187** 

Wanted output  

E-J1-N5,319319,240248,364364,**400400**  

F-J6-N1,380380,250250,360360,**400402**  

E-J6-N2,380380,240240,364374,**404406** 

So I need to substitute all occurrences of field1 (fileA) by field2 (fileA) but in another file, fileB (field $5). 

Here is what I though could work. Store in two variables: recordx (field1) and recordx (field2). My NOT working code: 

```
#!/bin/bash
for record in fileA
   do
        field1=`cut -d, -f 1 $record`
        field2=`cut -d, -f 2 $record`
        awk -v var1=$field1 -v var2=$field2 -F, '{sub(/var1/,"var2",$5);print}' fileB

   done

```

I get an error :  

awk: cannot open 175 (No such file or directory) 

Why is awk trying to open a variable ?
Am I heading in a good direction ?

Any help would be greatly appreciated !