The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #6 (permalink)  
Old 03-02-2006
gauravgoel gauravgoel is offline
Registered User
  
 

Join Date: Dec 2005
Location: India
Posts: 218
Quote:
Originally Posted by vino
What do you want to do ?

Find the number of occurences of a certain character in a string, or, are you looking for the all the positions where the character appears ?

For number of occurences you can do

Code:
echo "$string" | grep -c "r"
Hi Vino,

With due regards, I would like to say that the above may not solve the problem, OP is having. He is looking for no. of occurence of a character in a string. And the above command will give always give output as 1 if there is one or more than one occurence of "r"
Kindly correct me if I am wrong

Gaurav