"Simple" SED Problem

Hi all,

I have been trying to replace a word and a set of numbers with a hyphen and a leading zero (if required) but with failure.

For example the text "abc123" needs to be "abc-123" or "xyz1" needs to be "xyz-01".

In the case for the numbers i have been trying to place a leading zero if the number is below 10 but havent been able to do so :frowning: :confused:

My attempt was:

#!/bin/sh

INPUT=$1

RESULT=`echo $INPUT | tr "[:lower:]" "[:upper:]" |  sed 's/([A-Z])$/([A-Z])-/g' | sed 's/^\([0-9]\)$/0\1/g'`

echo "$RESULT"

Any suggestions please??

RESULT=`echo $INPUT |awk '{p=match($0,/[0-9]/);printf("%s-%02d\n",substr($0,1,p-1),substr($0,p))}'`

Regards

Thank you Franklin :b:

I also managed to get it through sed but thanks for your help:

for anyone interested in the sed way:

echo "abc123" | sed 's/[0-9][0-9]*/-&/' | sed 's/\(-\)\([0-9]\)$/\10\2/'