search and replace with data from another file

Can someone help me in solving the problem below.

I have the following two files

template_file
------------
...other data..
...other data..
FILE_NAME=
...other data..
...other data..

list_file
----------
<file_name1>
<file_name2>
<file_name3>

I need to produce another output file as

new_template_file
------------------
...other data..
FILE_NAME=/core/local/in/<file_name1> FILE_NAME=/core/local/in/<file_name2> FILE_NAME=/core/local/in/<file_name3>
...other data..
...other data..

Simply, I need to read the list file and prefix the path /core/local/in to the file names and then look for keyword FILE_NAME in the template and replace it with the file names that I received in list file.

I am not sure , but are you looking for something like this:

 
 
awk 'NR==FNR { a="FILE_NAME=/core/local/in/"$1 a ;next } $0 ~ /FILE_NAME/ {print a;next}{print $0}' list_file template_file

Thanks. It produced the following output

FILE_NAME=/core/local/in/file_name3FILE_NAME=/core/local/in/file_name2FILE_NAME=/core/local/in/file_name1

I am looking for an output of this format

FILE_NAME=/core/local/in/file_name1 FILE_NAME=/core/local/in/file_name2 FILE_NAME=/core/local/in/file_name3

Is there anyway in your solution you can introduce the space after each file name and also maintain the order that came in list file?

I tried below. But it also produces an unnecessary space in the beginning.

awk 'NR==FNR { a=" FILE_NAME=/core/local/in/"$1 a ;next } $0 ~ /FILE_NAME/ {print a;next}{print $0}' list_file template_file

What about invert the strings being concatenated to get the right order of files,

a=a "FILE_NAME=/core/local/in/"$1" "

in this case you get the extra space character at the end of the string, if still is relevant for you, try sub for delete the character

sub(/[ ]*$/, "", a)

before use it