Since I am not sure of what you need exactly, this is an example of running this command showing what it does:perl -pi.bak -e 's/ip-compute-[\d.]{7,15}-internal/ip-compute-10.25.25 +.25-internal/g' test.txt
Please note that this is a very very naive approach to IP address matching and that the [\d.]{7,15} pattern is only looking for any combination of 7 to 15 digits and dots. It might match many things other than IP addresses, such as a phone number (read carefully davido's caveats on the subject in his post above). In this specific case, however, one might argue that it is relatively safe to use this because the words "ip-compute-" and "-internal" coming respectively immediately before and after the numbers-and-dots matching part are making false matching relatively unlikely, but you are the only one to know the real content of the file you want to process and you are therefore the only one to be able to know whether this will be sufficient. If you need the match to be more selective, then you run into exactly the kind of problem that davido is describing: we probably don't want to reinvent the wheel.$ cat test.txt text.txt yoda yoda yoda ip-compute-10.10.10.1-internal yadda yadda yadda some more stuff $ perl -pi.bak -e 's/ip-compute-[\d.]{7,15}-internal/ip-compute-10.25. +25.25-internal/g' test.txt $ cat test.txt text.txt yoda yoda yoda ip-compute-10.25.25.25-internal yadda yadda yadda some more stuff
In reply to Re: Newbie regular expressions question
by Laurent_R
in thread Newbie regular expressions question
by bayareamonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |