Kerby82 Kerby82 - 5 months ago 7
Perl Question

How do I substitute a particular IP in a file with Perl?

I have a list of IPs, I have to transform all the lPs starting with

210.x.x.x
to
10.x.x.x


For example:

210.10.10.217.170
---->
10.10.10.217.170


Is there any in-line Perl regular expression substitution to do that?

I would like to have this substitution in Perl.

Answer

why don't you use sed instead ?

sed -e 's/^210\./10./' yourfile.txt

If you really want a perl script :

while (<>) { $_ =~ s/^210\./10./; print }