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
sample CSV:
192.168.001.000,any comment,host0003.zone.com
010.001.100.000,any long 000 string,host004.zone.com
should become
192.168.1.0,any comment,host0003.zone.com
10.1.100.0,any long 000 string,host004.zone.com
Any ideas?
Try
Regexp::Common
andNet::IP
if you don't mind using CPAN modules.Try this:
This works for your example data:
prints:
In any case, I strongly recommend that you use a CPAN module to parse the CSV file, like Text::CSV.
The unix regex below may help: