Problem: Need to read contents from a file and use that value inside sed as avariable. sample code below. THe below code replaces contents inside file123 for matched string with "$x" value only. but we want the value of x which is read from TextFile.txt to go in there.
cat TextFile.txt|while read x
do
cat file123 | sed -e 's/string1/$x/g'
done
Use double quotes instead of single quotes. This should work as long as $x does not contain forward slashes. This script will replace every string1 on every line in file123 with the first line of TextFile.txt, is that what you want to achieve?
By the way, you can avoid the double UUOC , like so:
while read x
do
sed "s/string1/$x/g" file123
done < TextFile.txt