我的IP地址列表,我不得不开始210.x.x.x
所有有限合伙人转变为10.x.x.x
如何用Perl替换文件中的特定IP?
例如:
210.10.10.217.170
---->10.10.10.217.170
有没有在线的Perl正则表达式替代做到这一点?
我想有这种替代在Perl。
我的IP地址列表,我不得不开始210.x.x.x
所有有限合伙人转变为10.x.x.x
如何用Perl替换文件中的特定IP?
例如:
210.10.10.217.170
---->10.10.10.217.170
有没有在线的Perl正则表达式替代做到这一点?
我想有这种替代在Perl。
你为什么不使用sed的呢?
sed -e 's/^210\./10./' yourfile.txt
如果你真的想要一个perl脚本:
while (<>) { $_ =~ s/^210\./10./; print }
我怀疑你想在那里有一个/ g。 Perl的等同于战略经济对话'的perl -pe的/^210 \ ./ 10./” yourfile.txt' – ysth 2010-11-17 14:56:45
$ip =~ s/^210\./10./;
# Read the IP list file and store in an array
$ipfile = 'ipfile.txt';
open(ipfile) or die "Can't open the file";
@iplist = <ipfile>;
close(ipfile);
# Substitute 210.x IPs and store all IPs into a new array
foreach $_(@iplist)
{
s/^210\./10\./g;
push (@newip,$_);
}
# Print the new array
print @newip;
你有你的输入文件的样本? – 2010-11-17 14:14:33
这些都不是有效的IP地址。 IP地址有四个部分 - 这些值有五个。 – 2016-07-07 10:38:23