'Using several variables in file, based on lines in other files
First post ever. I'll do my best :). I have no coding skills whatsoever, but am trying to learn, and have dabbled a bit in Linux.
So, I have a master document (master.txt). In this document, I would like to have a text including several variables, which are linked to other files (a.txt, b.txt, etc.), which can be changed manually. All this should produce a whole bunch of files.
So, lets say a.txt contains the following lines of text:
Mary
John
b.txt contains the following lines of text:
England
The US
Australia
master.txt contains this text:
"Hi there a, do you live in England?"
Now I would like to export several files at once, resulting in:
master_a1.txt: "Hi there Mary, do you live in England?"
master_a2.txt: "Hi there John, do you live in England?"
Then I'd slightly edit master.txt to:
"Hi there Mary, do you live in b?"
To produce:
master_b1.txt: "Hi there Mary, do you live in England?"
master_b2.txt: "Hi there Mary, do you live in The US?"
master_b3.txt: "Hi there Mary, do you live in Australia?"
I've been looking, searching and trying but cannot figure it out. The closest I came was based on something here on stackoverflow:
count=0
while read -r number; do
count=$(( count + 1 ))
printf 'Hi there %s, do you live in England?' "$number" >"/home/x/export/master_a"
done < ~/x/a.txt
Any help would be much appreciated! :D
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
