Le 23/01/2019 à 04:19, Adam Carter a écrit :
     > François-Xavier
     >
     >

    My bad, it should be:

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

    (tests are indeed needed!)


Many thanks François. This is almost right, but it is also stripping zeros that follow a letter, and I only want it to strip zeros that are proceeded by a period. There are no leading zeros in the first octet of the IP so that case does not need to be handled.

Does the \1 refer to what's in the ()'s? So anything that one would wont to carry through should be inside the ()'s and anything that's outside is stripped, right?




Yes, \1 is the content in (). But adding letters inside won't solve the problem, eg. "a01" will still be changed to "a1".

AFAIK, there is no way to express "start of line or a character" in sed, but you could do two regexps, one starting with ^ (start of line), the other with \. (dot)


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

Reply via email to