I am trying to edit my 'nginx.conf' file using a bash script intended to help users change environments quickly. The user enters their selected environment as an argument when running the script, which gets stored as a variable on the bash script. worker_processes  1;error_log  /usr/local/var/log/nginx/error.log;events {   worker_connections  1024;}http {   include       mime.types;   default_type  application/octet-stream;   sendfile        on;   keepalive_timeout  65;   #gzip  on;  server {     listen       80;     server_name  localhost;     merge_slashes off;     location ~\.(jsp)$ {        proxy_pass http://(environment_IP)     }     location ^~/r/ {        proxy_pass http://127.0.0.1:7300;     }     location ~*/wishlist{              proxy_pass http://(environment_IP)     }     location ~*/media/{               proxy_pass http://(environment_IP)     }     location ^~/data/{        proxy_pass http://(environment_IP)/data/     }     location ~*/static/{        proxy_pass http://127.0.0.1:7777;           }     location /{        proxy_pass http://127.0.0.1:7300/;     }  }   # HTTPS server   #   server {       listen       443 ssl;       server_name  localhost;       ssl_certificate      /etc/ssl/certs/myssl.crt;       ssl_certificate_key  /etc/ssl/private/myssl.key;       ssl_session_cache    shared:SSL:1m;       ssl_session_timeout  5m;       ssl_ciphers  HIGH:!aNULL:!MD5;       ssl_prefer_server_ciphers  on;       location ~\.(jsp)$ {                      proxy_pass https://(environment_IP)       }       location ^~/r/ {          proxy_pass http://127.0.0.1:7300;       }       location ~*/wishlist{                  proxy_pass https://(environment_IP)       }       location ~*/media/{                    proxy_pass https://(environment_IP)       }       location ^~/data/{          proxy_pass https://(environment_IP)/data/       }       location ~*/static/{          proxy_pass http://127.0.0.1:7777;       }       location /{          proxy_pass http://127.0.0.1:7300/;       }   }   include servers/*;}The issue I am running into is finding an optimal method to edit specific lines that are nested within my 'nginx.conf' file. Only certain instances of the 'proxy_pass' line is required to change such as the lines between 'location ~.(jsp)$' and 'location ~/wishlist*'. Furthermore, the IP at the end of 'location ^~/data/' must have the '/data/' string appended to the end. Lastly, I have to factor in the different instances of http and https that are within the configuration file. I have tried to edit the values after 'proxy_pass' using sed, however I do not know how to only change specific values that are nested within text. I am a beginner to regular expression, the code I wrote so far finds proxy_pass but changes all instances following the string.sed s/.*proxy_pass.*/proxy_pass testpost/All comments and suggestions are appreciated, Thanks!
Editing nested text and specific lines within a file using bash script
bash;sed;nginx
If your config is regular enough, and assuming you're already splitting it up into small separate files, it will probably be easier to regenerate the whole file from scratch each time, in which case it could be as easy as#!/bin/shENV_IP=$1cat > nginx.conf <<EOF......location ^~/data/{      proxy_pass https://$ENV_IP/data/}......EOF