0
(?<![0-9])0+(?=[0-9]+)

I need to remove unnecessary leading zeros in malformed octettes of IP addresses.

I want to do something like this but it is not working.

cat Qualys-Active-IPs.csv | awk -F';' {'print $1'} | sed 's/(?<![0-9])0+(?\=[0-9]+)//g'
overflyer
  • 1
  • 1

2 Answers2

0

The solution is:

 sed -r 's/^0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)$/\1.\2.\3.\4/'
overflyer
  • 1
  • 1
0

You may try this code:

sed -r 's/^0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)-0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+)\.0*([0-9]+),...,(.*)$/\9:\1.\2.\3.\4-\5.\6.\7.\8/' 
J...S
  • 5,079
  • 1
  • 20
  • 35