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
Post a Comment