Reputation: 428
I have string "001.036.020" and I need to convert it to "1.36.20". Saying other words I need to remove all "0" before digit. Is it possible to do this using sed?
Upvotes: 1
Views: 789
Reputation: 785058
This sed should work:
sed 's/0*\([1-9]\)/\1/g'
EDIT: To handle more complex cases like:
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'
Upvotes: 3