So basically I have a text file with a lot of blank lines. Let's call it time.txt and a part of this file looks like this:
1 5 20
2 5 12
1 6 3
2 6 4
1 10 30
2 10 21
1 11 27
2 12 8
1 11 34
2 12 20
1 10 30
2 10 21
Now, I have another file, called location.txt, which contains the same number of lines as the number of blank lines in time.txt. It looks like this:
110 -7 5.000 66
110 -7 5.000 99
110 -7 5.000 60
And what I want is actually simple: I just want to fill the blank lines in time.txt with each line in location.txt, giving the intended results:
110 -7 5.000 66
1 5 20
2 5 12
1 6 3
2 6 4
110 -7 5.000 99
1 10 30
2 10 21
1 11 27
2 12 8
1 11 34
2 12 20
110 -7 5.000 60
1 10 30
2 10 21
My way to solve this is by reading line by line location.txt, store each line in a variable within the loop, and then using awk to detect empty lines inside time.txt and replace it with stored loop variable. My code looks like this:
time="time.txt"
location="location.txt"
while read -r lines_locs; do
awk '!NF{$0=$lines_locs}1' $time
done < "$location"
but this only prints out time.txt in my screen with no replacements made. Plus, I had too many lines printed compared to the expected number of lines. I'm sure that I'm missing something and I would be glad if someone can point this out.