using nawk

help out with code. two files aaa bbb contains some records..output file xyz should be like this..see below
i/p file:aaa

08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878

i/p file: bbb

60521|60510

o/p file :xyz

60510|08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878

nawk -F'|' 'FNR==NR{f2[$1]=$2;next} $2 in f2 {$1=f2[$2] OFS $1}1' OFS='|' bbb aaa > xyz

its also printing record in aaa. like this

output:

08350|60321|0000|505|0000|1555|000|NYCMT|Pd_1 |-3023.38
60510|08350|60521|0000|505|0000|1555|000|NYCMT|Pd_1 |-11878|

Had you given a more representative sample AND a desired output based on this sample, we could have provided a better solution....
Once again - guessing what you're after....

nawk -F'|' 'FNR==NR{f2[$1]=$2;next} $2 in f2 {$1=f2[$2] OFS $1;print}' OFS='|' bbb aaa > xyz
awk 'BEGIN{FS=OFS="|"}{a[$1]=$2}NR>FNR && a[$2] {print a[$2],$0}' bbb aaa

thanks vgersh99 n yinyuemi