You can assign to an array the list of strings that will replace to <>.
In a file called list.txt you should have:
test
dev
too
And in a file called data.txt you should have:
22<>22
3<>33
134423<>4
Solution 1:
Reading the file list.txt and assign its content to an array.
Read array using bash
export IFS=$'\n'
readarray array < list.txt
Read array using zsh
array=("${(@f)"$(<list.txt)"}")
Finally you have to iterate over array variable to get each element of the list and replace with sed:
for i in ${array[@]}; do
sed "s/<>/$i/g" data.txt
done
Note: The for loop will print the text to the stdout (in your terminal). But if you want to redirect the output to a file, you can use > after done keyword:
for i in ${array[@]}; do
sed "s/<>/$i/g" data.txt
done > final.txt
This solution will produce an output like this:
22test22
3test33
134423test4
22dev22
3dev33
134423dev4
22too22
3too33
134423too4
Solution 2:
First you will have to read the file list.txt and assign its content to an array.
Read array using bash
export IFS=$'\n'
readarray array < list.txt
Read array using zsh
array=("${(@f)"$(<list.txt)"}")
After that you have to iterate over each line of file data.txt and inside that loop read each item from the array to apply the sed command:
while read line ; do
for i in ${array[@]}; do
sed "s/<>/$i/g" <<< "$line"
done
done < data.txt
Or redirecting the stdout to a file:
while read line ; do
for i in ${array[@]}; do
sed "s/<>/$i/g" <<< "$line"
done
done < data.txt > final.txt
This solution will produce the following output:
22test22
22dev22
22too22
3test33
3dev33
3too33
134423test4
134423dev4
134423too4
-f