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.
#!/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
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