This question really bothered me much. What i want is to replace any times of repeated 'TB' to 'T', below is example.
It can be fullfil by AWK and perl, but my desire is using SED to realize it.
So here means we treat TB as a whole part, which means 's/TB*/T/' and
's/[TB]*/t/' can not fullfill it.
Maybe it is too early in the morning but what is different about the last line i.e. 'aTBTTBTBe' ? It has the pattern 'TB' in it. Surely it should change to 'aTTTe"
#!/bin/ksh
for i in $*
do
z=$(echo $i | grep TT)
if [ x"$z" = x ]
then
z=$(echo $i | sed -e 's/TB/T/g')
while [ 1 ]
do
z=$(echo $z | sed -e 's/TT/T/g')
if [ x"$(echo $z | grep TT)" = x ]
then
break
fi
done
echo $i/$z
else
echo $i/$i
fi
done