I’ve got a script which writes an ip address to a file ip.txt
I want to replace an ip address in an html file with the ip from ip.txt.
I’ve got a sed regex expression that matches an ip address, and I want to replace this matched text with the contents of ip.txt:
"s/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}//g"
How can I get sed to pull the contents of ip.txt and put it in the expression s/<search>/<*HERE*>/g?
Is there a better way to do it than this?
sed -e "s/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/"`cat ip.txt`"/g"
You can read the IP into a shell variable before running the sed command. Assuming that ip.txt is a single line containing only the IP address: