The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 03-02-2006
Sniper Pixie Sniper Pixie is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 25
Thanks for your reply, but I want it to loop through the string and then perform an action for each occurrance of r, not just once. eg. "rover" would return 11 in this example because there're two r's in it.

I've tried adapting your code so it looks something like this:

echo $string | awk '{
for (i=1;i<=length($0);i++)
do
if [[ (substr($0,i,1) == *r*) ]] ; then
echo "1"
fi ;
done
}'


but get parse errors all over the place:

awk: cmd. line:4: if [[ (substr($0,i,1) == *r*) ]] ; then
awk: cmd. line:4: ^ parse error
awk: cmd. line:4: if [[ (substr($0,i,1) == *r*) ]] ; then
awk: cmd. line:4: ^ parse error
awk: cmd. line:4: if [[ (substr($0,i,1) == *r*) ]] ; then
awk: cmd. line:4: ^ parse error

Any more ideas?