search in finding position of a string in avariable

Hi,

I have to find a text in a variable and need to get the position of it. say,

a="This is Example Example1 xxx yyy Example"

if i search for "Example" then i should get the location of the starting location "Example".
and in next iteration it should give the location of next "Example"

is there any easy way to do this?

Thanks in advance,
-Raja

pretty simple with perl:

$_= 'This is Example Example1 xxx yyy Example';
print +(pos) - length('Example'),"\n" while (/Example/g);

probably as simple with other shell scripts.

if you can use Python

#!/bin/sh
python << EOF
a="This is Example Example1 xxx yyy Example"
print [n for n,i in enumerate(a.split()) if "Example" in i]
EOF