#!/bin/bash
echo 'server {
location /test/v2.0.3 {
modsecurity on;
proxy_pass http://10.1.0.6:3000;
}
location /test/v2.0.0 {
modsecurity on;
proxy_pass http://10.1.0.6:3000;
}
}' | sed -r '\!^\s+location /test/v2.0.0 \{!,/^\s+\}$/ s/:3000;/:5555;/'
#!/bin/bash
line=`grep -n '^ *location' myfile | sed -rn '1s/(.+):.+/\1/p'` # номер первой строки с location
sed -ri "$line s/.+/0000\n&/" myfile
каждая вставляемая строка должна оканчиваться слэшом
#!/bin/bash
location='
location /projects/test/v2.0.1-4 {
proxy_pass http://0.0.0.0:2222;
}'
sed -i "
/modsecurity/i ${location//$'\n'/\\$'\n'}
" MYFILE
echo 'CONFIG="USER OUTPUT"' | sed -r 's/(CONFIG="USER OUTPUT)"/\1 CONSOLE"/'
sed '3a\ if ($host = www.'$1') {return 301 https://'$1'$request_uri;}' /etc/nginx/vhosts/vach
sed "3a\ if (\$host = www.$1) {return 301 https://$1\$request_uri;}" /etc/nginx/vhosts/vach
sed -i '\| include bx/conf/ssl.conf| { s| include bx/conf/ssl.conf|#&|; a\
ssl_certificate /etc/letsencrypt/live/mfwo.ru/fullchain.pem;\
ssl_certificate_key /etc/letsencrypt/live/mfwo.ru/privkey.pem;\
ssl on;\
keepalive_timeout 70;\
keepalive_requests 150;\
ssl_session_cache shared:SSL:10m;\
ssl_session_timeout 10m;
}' /tmp/test.conf
Можно вместо `........` использовать $(..........), тогда будет работать как в первом случае