how to trim leading 0, not at beginning of alphanumeric string with `sed`

69 Views Asked by At

given examples:

A10
A01
A1
B09
B80
C11

how to trim leading zero's retaining alphabet, using sed?

expected results from source examples:

A10
A1
A1
B9
B80
C11

^[0] does not apply here because it's not beginning of string. matching [A-Z][0] could work, but need result to retain the [A-Z] and i don't know how to do so.

1

There are 1 best solutions below

1
RomanPerekhrest On

With sed substitution:

sed -E 's/^([A-Z])0?([0-9]+)/\1\2/' test.txt
  • 0? - matches optional zero between captured groups

A10
A1
A1
B9
B80
C11