count the number chracters occurances in a line

Hi

Could anybody tell me how to count the number of occurances of a character within a LINE.

actually i have a single line with words seperated with '+' chracter e.g.

abc+def+ghj+jkl+asd

i want to separte the words above.

Please provide the necessary logic in the form of a SHELL SCRIPT.

Thanks in advance

line=abc+def+ghj+jkl+asd
echo "Line length : ${#line}"

FOUND THE ANSWER :slight_smile:

#!/usr/bin/sh

VALUE="+ABC+DEF+MGH+THY+MGH+hjk+fyf"
count=0
no_fields=`echo "$VALUE" |awk -F"+" '{print NF}' `
no_fields=`expr $no_fields - 1`
echo "The number of + are $no_fields"

above can be done as,

echo $VALUE | awk -F"+" '{ print NF }'

Thanks

Could you help me regarding my other query also.
its just adjacent to this one.

echo "abc+def+ghj+jkl+asd" | awk -F"+" '{ for ( i=1; i<=NF; i++ ) { printf "%s\n", $i }}'

Thanks dude.

Just a modification to this is required

The initial string is like this
+abc+def+ghj+jkl+asd

Please note the + in the beginning also. i am having the whole string in a variable called VALUE and i want the new value of the varaiable to be
abc, def, ghj, jkl, asd

i.e removing starting + and repacing with ,<space> elsewhere with new string to be placed in the same varaiable.

Thanks