仅在IP地址中删除前导零 [英] Remove leading zeros only in IP addresses
本文介绍了仅在IP地址中删除前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从所有IP地址中删除csv中的所有前导零,而不是其他(如主机名)。
I need to remoe all leading zeros in a csv from all IP addresses, but not others (like hostnames).
我得到以下内容,它会删除所有
I got the following, which does remove all
s/(?<!\d)0+(?=\d)//g
样本CSV:
192.168.001.000,any comment,host0003.zone.com
010.001.100.000,any long 000 string,host004.zone.com
应该成为
192.168.1.0,any comment,host0003.zone.com
10.1.100.0,any long 000 string,host004.zone.com
任何想法?
推荐答案
尝试 Regexp :: Common
和 Net :: IP
如果您不介意使用CPAN模块。
Try Regexp::Common
and Net::IP
if you don't mind using CPAN modules.
$ <sample.csv perl -MRegexp::Common -MNet::IP -ple 's/($RE{net}{IPv4})/Net::IP->new($1)->ip/ge'
这篇关于仅在IP地址中删除前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文