I need to add the contents of a text file between certain placeholders in another text file. (Specifically, I'm trying to get around the nginx include limitation inside upstream blocks.)
My main nginx configuration file /etc/nginx/nginx.conf
looks like this:
## START UPSTREAM
## END UPSTREAM
http {
...
}
My server upstream file /etc/nginx/upstream.conf
looks like this:
upstream wordpress {
server 10.0.0.1;
server 10.0.0.2;
...
}
I want to copy the contents of /etc/nginx/upstream.conf
in between the ## START UPSTREAM
and ## END UPSTREAM
blocks. The desired result:
## START UPSTREAM
upstream wordpress {
server 10.0.0.1;
server 10.0.0.2;
...
}
## END UPSTREAM
http {
...
}
So far, I've tried to use sed
(with the help of other StackOverflow solutions):
sed -i '/## START UPSTREAM/,/## END UPSTREAM/ r /etc/nginx/upstream.conf' /etc/nginx/nginx.conf
However, the above code doesn't work--it just fails silently. How can I modify sed to properly replace all text between the placeholders?
Thanks in advance!