我的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