Search this Website

 

Ubuntu

UNIX

trim leading zero in certain column in a string

Category: UNIX-Unix Beginner

trim leading zero in certain column in a string

i would like to know how to trim leading zero only in certain column of of a string, example:

hdhshdhdhd000012mmmm0002abc <===== before
hdhshdhdhd 12mmmm 2abc <===== after

thanks for your help.


code:
echo "hdhshdhdhd000012mmmm0002abc" | sed "s/0\{1,\}\([1-9]\{1,\}\)/ \1/g"


or other options:

code:

sed 's/\([^0]\)0\{1,\}/\1 /g'
or
code:

sed 's/\([^0]\)00*/\1 /g'[img]http://www.unix.com/images/buttons