Hi 
I am writing a ksh
I have a string of general format
A12B3456CD78
the string is of variable length
the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7)
before these ending numbers are alphabets (here it is CD can even be C alone or CDX ..that is length can be varied)
before the CD is a string of variable length that always ends in digits here A12B3456 ....
i want to extract each of these seperately ..
ie
part one A12B3456
part two CD
part three 78
this is a bit complicated for me
... plz help me out
anbu23
2
echo A12B3456CD78 | sed "s/\([0-9]*\)$/\\
\1/" | sed "1 s/\([a-zA-Z]*\)$/\\
\1/"
vino
3
[/tmp]$ cat ./try.ksh
#! /bin/ksh
in=A12B3456CD78
f3=$(echo $in | tr '[A-Z]' ' ')
f3=${f3##* }
in=${in%$f3}
f2=$(echo $in | tr '[0-9]' ' ')
f2=${f2##* }
f1=${in%$f2}
echo "$f1"
echo "$f2"
echo "$f3"
[/tmp]$ ./try.ksh
A12B3456
CD
78
[/tmp]$
# !/opt/third-party/bin/zsh
str="A12B3456CD78"
only_num=$(echo $str | tr '[A-Za-z]' ' ' | awk '{print $NF}')
only_alpha=$(echo $str | tr '[0-9]' ' ' | awk '{print $NF}')
echo $str $only_num $only_alpha | awk '{ print (substr ($0,0,length($1) - ( length($2) + length($3) ))), "\n", $2, "\n", $3 }'
exit 0