Copying number by looking a large file

Hi All,

I have a big file which looks like this:

abc 34.32
cdf 343.45
computer 1.34
ladder 2.3422

I have some 100000 .TXT files which look like this:

computer
cdf
align

I have to open each of the text files and read the words from the text files. Then I have to look into that dictionary for the occurrence of the word and copy on the number in 1.num file. This is what I mean:

Contents of 1.num

1.34
343.45
0

As you can see, I have copied the numbers matching with words in 1.txt from that big file. 0 for no-occurrence.

I have to do this for all 100000 .txt files.

I have tried some lookup techniques but not working though.

for txt in *.txt; do                                                         
  awk '
     NR == FNR { a[$1]=$1 }
     NR != FNR { print $1, a[$1] }
  ' big_file.dat $txt >${txt%txt}num
done

I am doing this in Linux with BASH

for txt in *.txt; do                                                         
  awk 'NR==FNR{a[$1]=$2;next} {print a[$1]==""?"0":a[$1]}' big_file.dat $txt  > ${txt%txt}num
done
1 Like

Seems it is not giving me the required output. What it is showing me in 1.num are the "words" which have matched rather than numbers, as I have shown in the example above. I am trying to edit your code and make it work. If I can do it, I'll post it here.

---------- Post updated at 01:27 PM ---------- Previous update was at 01:12 PM ----------

I am sorry. Its fine. It was the problem with my data file. Really sorry.