file1:
id dept
123 555
123 777
123 555
321 888
321 999
321 111
231 582
231 592
231 986
file2
id dept
123 555
321 888
231 582
In file 1 id field is showing different dept numbers. But they are to
be replaced with the equalent file2 dept filed. The oupt should be
like.
id dept
123 555
123 555
123 555
321 888
321 888
321 888
231 582
231 582
231 582
I tried like this.
awk 'NR==FNR{
idfl1=$1
deptfl1=$2
1file[idfl1]=idfl1
next
}{
idfl2=$1
deptfl2=$2
if(idfl2 in 1file)
print idfl1,deptfl2
}'
but it is not giving required output
(assuming the header line is not part of the files)
awk 'NR==FNR{dept[$1]=$2;next}{print $1, dept[$1]}' file2 file1
^ what version of awk are you running that allows variable names to
start with a number?
Ed.
sorry! by mistake i defined it on this post, but actually not.. thank
you