To increment the values from the file

Hi

I have the file called "file.txt" which contains the following output

$cat file.txt
sandy
<version>1</version>
karen
<version>2</version>
Rob
<version>3</version>
peter
<version>4</version>

i want to write a command which will add the value 1 to the digits and show the output like this.

sandy
<version>2</version>
karen
<version>3</version>
Rob
<version>4</version>
peter
<version>5</version>

I have tried using some commands but it seems it is not working or i think i am wrong somewhere :confused:.

$ cat file.txt | grep "<version>" | sort -r | uniq | while read line
do
n=`echo $line | cut -f2 -d"<" |cut -f2 -d">"`
nn=`expr $n + 1`
newb="<version>$nn</version>"
sed 's;'${line}';'${newb}';g' file.txt >> file1.txt
mv -f file1.txt file.txt
done

Please help me resolving this problem.

Regards
Siddharth

bash-3.00$ nawk -F"[<|>]" ' { if($2=="version") {printf("<%s>%d<%s>\n", $2,$3+1,$4)} else {print $0}}' /tmp/myfile
sandy
<version>2</version>
karen
<version>3</version>
Rob
<version>4</version>
peter
<version>5</version>

Thanks a lot. Its working fine..