|
if statement in for loop of a string
I am attempting to pass a string into awk and loop through it, and then for every occurrance of a certain character perform an action. In this case, for example, echo 1 for each time character r is found in the string. Except I can't get it to work. Could someone please tell me why?
echo $string | awk '{
for (i=1;i<=length($0);i++)
do
if (substr($0,i,1) == "r")
echo "1"
fi
done
}'
|