regex - Remove leading zeros only in IP addresses -


I need to remove all the leading zeros in CSV from all the major addresses, but others (such as hostname).

I got the following, which removes everyone

  s / (?   

sample CSV:

  192.168.001.000, any comment, host0003.zone.com 010.001.100.000, any long 000 string, host004.zone Com   

should be

  192.168.1.0, no comment, host0003.zone.com 10.1.100.0, 000 string any longer, host004 .zone.com   

Any ideas?

Try Regexp :: Common and net :: ip If you do not use CPAN module

  $ < Sample.csv perl -MRegexp :: General -Mainnet :: IP -play '/ / ($ RE {net} {IPv4}) / Net :: IP-> New ($ 1) - & gt; Ip / ge '   

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -