emitter
emitter

Reputation: 69

How to replace a random IP-address in a file (Perl, Windows)

How can I replace a random (unknown) IP-address in a TXT file using Windows Perl? (unfortunately I only found solutions mostly for Linux/sed)

My textfile contains FTP commands, containing only one IP address:

open ftp://user:[email protected]
cd c:/temp
mkdir newdir

etc.

I tried this, but it did not change anything.

perl -pe s/[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/10.10.111.222/g FtpCommands.txt > FtpCommands_mod.txt

Thanks!

Upvotes: 2

Views: 259

Answers (1)

Shawn
Shawn

Reputation: 52614

If your file has an IPv4 address, using the Regexp::Common module makes this an easy one-liner:

perl -MRegexp::Common=net -pe "s/$RE{net}{IPv4}/10.10.111.222/" FtpCommands.txt > FtpCommands_mod.txt

Upvotes: 4

Related Questions