regex - How to remove 0 from a string using sed -


i have string "001.036.020" , need convert "1.36.20". saying other words need remove "0" before digit. possible using sed?

this sed should work:

sed 's/0*\([1-9]\)/\1/g' 

edit: handle more complex cases like:

  • 0s in between digits:
  • handle segment 0s (would collapsed single zero)

on linux:

sed -r -e 's/(^|\.)0+([1-9])/\1\2/g' -e 's/(^|\.)(0)0*(\.|$)/\1\2\3/g' 

or on mac:

sed -e -e 's/(^|\.)0+([1-9])/\1\2/g' -e 's/(^|\.)(0)0*(\.|$)/\1\2\3/g' 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -