Combining columns from different files

I have two files I need to combine. The problem I'm having is I need to only combine data from the second file in the empty spaces of the first. For example:

file1
Data Field

Data Field
Data Field

Data Field

file2
a - Insert Data
b - Insert Data
c - Insert Data
d - Insert Data
e - Insert Data
f - Insert Data

Output file
file3
Data Field
b - Insert Data
Data Field
Data Field
e - Insert Data
Data Field

I'm thinking of awk but I'm not sure on where to start. I would appreciate if someone could direct me on where I can learn more on how to do this.

This might work...

 
awk 'NF=0{print NR}' file1 >> blank_line_numbers
for i in `cat blank_line_numbers`
do
insert_line=`head -$i file2 | tail -1`
sed 's/^$/$insert_line/$i' file1 >> temp
mv temp file1
done

You can try the following bash script.

#!/bin/bash
PATH=/usr/bin:/bin
export PATH

exec 3<file1
exec 4<file2

while read a 0<&3; do
        read b 0<&4
        echo ${a:-$b}
done

# this line will output any remaining lines in file2
# if you don't need this, then you can take it out
cat <&4

I try to resolve this with command awk, but i have problems...
I try this...

awk 'NR==FNR{a[NR]=$0;next}{b[FNR]=$0}END { for(i=1;i<=FNR;i++) if (b=" ") b=a}{print i,b}' file1 file2

please advice.

nawk 'FNR==NR {f1[FNR]=$0;next} {print NF?$0:f1[FNR]}' file2 file1

great, magic...but i don't understand this part....

nawk 'FNR==NR {f1[FNR]=$0;next} {print NF?$0:f1[FNR]}'

Could you explain please .....

Thanx

you can rewrite this as:

nawk 'FNR==NR {f1[FNR]=$0;next} 
                        {
                           if (NF!=0) 
                              print $0
                           else
                              print f1[FNR]
                        }' file2 file1 

Thanks everyone for you help. The one I went with was

paste -d "|" f1 f2 | awk -F "|" '
{ if ( $1=="" ) { print $2}
else {print $1}
}' > f3

thanks to Jadu Saikia

HI Protocomm,

the logic is if the number of field is greater than zero then it will print $0(which is the current line of file1 and if the number of field is zero then it will frint the second argument which is f1[NFR].

a?b:c
it mean if a is true then excute b else excute c

regards,
Sanjay

Thanks for the explanation.

as long as your two files contain same number of rows, below one should be ok.

paste -d"," f1 f2 | awk -F"," '{if($1=="") print $2; else print $1}'