Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何替换文件中的随机IP地址(Perl、Windows)_Windows_File_Perl_Replace_Ip Address - Fatal编程技术网

如何替换文件中的随机IP地址(Perl、Windows)

如何替换文件中的随机IP地址(Perl、Windows),windows,file,perl,replace,ip-address,Windows,File,Perl,Replace,Ip Address,如何使用Windows Perl替换TXT文件中的随机未知IP地址? 不幸的是,我只找到了主要针对Linux/sed的解决方案 我的文本文件包含FTP命令,仅包含一个IP地址: open ftp://user:password@123.123.123.123 cd c:/temp mkdir newdir 等等 我试过这个,但没有改变任何事情 perl -pe s/[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/10.10.111.222

如何使用Windows Perl替换TXT文件中的随机未知IP地址? 不幸的是,我只找到了主要针对Linux/sed的解决方案

我的文本文件包含FTP命令,仅包含一个IP地址:

open ftp://user:password@123.123.123.123
cd c:/temp
mkdir newdir
等等

我试过这个,但没有改变任何事情

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

谢谢

如果您的文件具有IPv4地址,则使用该模块可以轻松实现这一点:

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

是匹配IP地址的良好起点。请使用双引号。。。Windows命令行上的s/$RE{net}{IPv4}/10.10.111.222/谢谢你们两位!它使用Regexp模块在Windows上工作,也可以不使用它:perl-MRegexp::Common=net-pes/$RE{net}{IPv4}/10.10.111.222/FtpCommands.txt>FtpCommands_mod.txt perl-pes/[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/10.10.111.222 FtpCommands.txt>FtpCommands.txt>FtpCommands.mod。txt@mob完成。不过看起来很有趣。那么,我假设标准windows shell不使用$进行变量替换?