Reputation: 69
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
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