0

I have a problem when I'm trying to regex a line in a document with sed. Here is what I want to regex:

proxy_pass http:\\193.168.19.35/;

I want to obtain the following result:

proxy_pass http:\\193.168.19.32/;

This is what I have tried:

sed -r 's/^proxy_pass htpp\:\/\/[[:digit:]]+.*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp

Can you guys help me here?

3
  • 3
    misspelling? htpp -> http? Commented May 27, 2015 at 17:32
  • 1
    No matter how many times you replace something with 192.168.81.29, it will never end up with the result 193.168.19.32... Making your question consistent would probably be a good idea... Commented May 27, 2015 at 21:04
  • See stackoverflow.com/questions/29613304/… Commented May 28, 2015 at 2:50

1 Answer 1

2

If you have a URL with \\, you need to add support for this pattern in your regex. I believe you just misspelt some words in your question.

So, if you want to match proxy_pass http:\\193.168.19.32/;, use

sed -r 's/^proxy_pass http\:\\\\[[:digit:]]+(\.[[:digit:]]+)*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp
                            ^^^^            |---------------|

If you want to replace proxy_pass http://193.168.19.32/;, use

sed -r 's/^proxy_pass http\:\/\/[[:digit:]]+(\.[[:digit:]]+)*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp
                            ^  ^            |---------------|

Pay attention to (\.[[:digit:]]+)* in the pattern, it makes it possible to match all the 4 parts of the IP address.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.