bash - Problems in mapping indices using awk -


hi have data files

file1

1   hero 2   chainsaw , gang 3   ......... 4   ......... 

where first field id , second field product name

file 2

the hero 12 hero 2 chainsaw , gang 2 ....................... 

from these 2 files want have third file

file 3

the hero 12 1 hero 2 1 chainsaw , gang 2 2 ....................... 

as can see adding indices reading file 1

i used method

awk -f '\t' 'nr == fnr{a[$2]=$1; next}; {print $0, a[$1]}' file1 file2 > file 3 

where creating associated array using file 1 , doing lookup using product names file 2

however files huge, have 20 million product names , process taking lot of time. suggestions, how can speed up?

you can use awk:

awk 'fnr==nr{p=$1; $1=""; sub(/^ +/, ""); a[$0]=p;next} {q=$nf; $nf=""; sub(/ +$/, "")}      ($0 in a) {print $0, q, a[$0]}' f1 f2 hero 12 1 hero 2 1 chainsaw , gang 2 2 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -