Variables in a text file

I have a text file with four variables in it (eg. AA, BB, CC and DD - AA and BB are on the same line separated by a space and CC and DD are on the next line separated by a space).

In the body of my code, I want to define the variables as some kind of text (eg. AA=store, BB=bank, CC=gym and DD=park).

Also in the body of my code, I have four sentences. (eg. The man went to the <insert variable AA>, The woman went to the <insert variable BB>, The girl went to the <insert variable CC>, and The boy went to the <insert variable DD>).

The ultimate goal is to define a number of variables in the body of the code and only have to edit the text file (add new variables EE, FF, GG, HH, etc. following the same pattern as above), change the <insert variable name> as desired and have everything outputted to a new text file. I do not know how to call the variables from the text file and have them run properly in the code though. Can anyone help point me in the right direction? Thanks.

I don't think the contents of the text file can be called "Variables".

Use four String variables in your code, in your case AA,BB,CC,DD. Now before you print the statement, just make sure that you strcpy() the contents of the file in the respective variable. It can be arranged so that 1 variable is used per line. So load the first line of text from the file to AA and so on. Now print the statements, something like:

m4 or TeX are good macro languages for the task---except that these would require rewriting the dictionary.
I'd use gawk since it has associative arrays built in.
This gawk program substitutes on each line from left to right rescanning the full line. Therefor nested substitutions and infinite loops are possible.

Code:

# store this program in file dwl.gawk
# use: gawk -f dwl.gawk dictionary template
# example:
#
# dictionary
#AA=store
#BB=bank
#CC=gym
#DD=park
#
# template
#Also in the body of my code, I have four sentences. (eg. The man went to the <insert variable AA>, The woman went to the <insert variable BB>, The girl went to the <insert variable CC>, and The boy went to the <insert variable DD>
#
# result
#$ gawk -f dwl.gawk dict template
#Also in the body of my code, I have four sentences. (eg. The man went to the store, The woman went to the bank, The girl went to the gym, and The boy went to the park
{
if (FILENAME==ARGV[1]) {
if (2 == split($0,a,/=/)) {
dict[a[1]] = a[2]
}
} else {
for (i = match($0,/<insert variable [[:alpha:]]+>/); i ; i = match($0,/<insert variable [[:alpha:]]+>/)) {
x = substr($0,1,i-1) # the text up to next <
j = match(substr($0,i),/>/)
y = dict[substr($0,i+17,j-18)] # the dictionary substitution
z = substr($0,i+j) # the text following >
$0 = x y z
}
print
}
}

I'm having a lot of trouble understanding your problem, especially the roles of the "text file" and "body of code." Anyway, here's my solution to an approximation of your problem (in PHP). [php=example.php]<?php $AA = "store"; $BB = "bank"; $CC = "gym"; $DD = "park"; ?>
The man went to the <?php echo $AA?>,
the woman went to the <?php echo $BB?>,
the girl went to the <?php echo $CC?>,
and the boy went to the <?php echo $DD?>.
[/php](run with: php example.php)