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....
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 ...