How do i use sed to replace string with values from a dictionary file

I have file 1 with one million rows. one of the fields is
"FIRSTNAME" (the string)
I have a second file with about 20 first names.

JUDE
DAVID
HOMER
CANE
ABEL
MARTY
CARL
SONNY
STEVE
BERT
OSCAR
MICKY
JAMES
JOHN
GLENN
DOUG
ERNIE
CECIL
KENNY
KEVIN
LARRY
MING
ROCKY
RONNY
GREGG

I want to either recursively, or randomly (it really doesn't matter)
replace "FIRSTNAME" with a value from the second file .

I know how to replace and space fill FIRSTNAME with MING, for example,
but then my whole document is full of MING.

I looked and couldn't find an answer to my conundrum... I have many
more operations to perform, but they are all of the same kind.

Thanks for your input.

Lionel

awk ' FILENAME=="smallfile" {arr[cnt++]=$0}
        FILENAME=="bigfile" { tmp=sprintf("%9s", arr[FNR % cnt]);
                                     gsub(/FIRSTNAME/, tmp) 
                                      print $0 }'  smallfile  bigfile > newfile

You guys make me want to cry! :slight_smile:

had to use /usr/xpg4/bin/awk, but beyond that, it works wonderfully. THANKS YOU for saving my night.

I'm such a hack!

recursively:

nawk 'NR==FNR{names[NR]=$0;max=NR}NR!=FNR{ind=NR%max;if(ind==0){ind=max}$1=names[ind];print $0;}' file1 file2