bash search and replace

Hello all,

I would like to replace some text that are forwarded in standard output from a script, then save the replaced text to a file.
The text i would like to replace is in the form of:

1 some text
1.1 other text
1.2 more text
1.2.1 still more text

i would like to replace
1 some text by T1 some text
1.1 other text by T2 other text
1.2 more text by T2 more text
1.2.1 still more text by T3 still more text
and so on....

Any help appreciated, thank you.

I started with this :

first_script.sh | awk '/^([[:digit:]]|[[:digit:]].)+[[:blank:]]/ {print}'

Instead of printing i would like to replace as explain in the first post.

I've got another solution but still dont know how to replace the text:

first_script.sh | while read line
        do
                isTitle=$(echo $line | grep "^[[:digit:]]")
                if [ "$isTitle" ]
                then
                        echo $line
                fi
        done

ok, i almost done it:

while read line
        do
                isTitle=$(echo $line | grep "^[[:digit:]]")
                if [ "$isTitle" ]
                then
                        num=${line%%[[:blank:]]*}
                        echo $num
                        length=${#num}
                        if [ $length -eq 1 ]
                        then
                                title=T$length
                        else
                                echo
                        fi
                        echo "title : $title"
                fi
        done

just have to do the algorithm for determining the level of title: 1, 2, 3 ...

while read line
        do
                isTitle=$(echo $line | grep "^[[:digit:]]")
                if [ "$isTitle" ]
                then
                        num=${line%%[[:blank:]]*}
                        echo $num
                        length=${#num}
                        level=$(echo $length * 1/2 + 1/2 | bc)
                        title=T$level
                        echo "title : $title"
                fi
        done

Can someone help on how to use bc ?? I have an error at the moment, it doesn't take the variable. How can i pass it ?

> length=12
> level=$(echo "${length} * .5 + .5" | bc)
> echo ${level}
6.5