Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I count . in a string ? 1

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
I have the following strings and I need to count the number of .s
JOBNAME_123.1.3
JOBNAME_234.1
JOBNAME_345

My result should be ;
2
1
0

I tried grep -c "\." but only get 1.
 
Sorry, this isn't an answer, but grep -c counts the lines with the string, rather than occurences of the string. Cheers.
 
Hi Tison,
in ksh script you can do

A=JOBNAME_123.1.3
B=`echo $A|tr -d "."`
((DotNumb=${#A}-${#B}))

Regards Boris
 
When I run the script I get ;
./getln[3]: DotNumb=JOBNAME_123.1.3-JOBNAME_12313: 0403-009 The specified number is not valid for this command
 
Hi Tison,
check you don't forgot # in line 3.
${#A}-${#B}
not
${A}-${B}
Boris
 
Yes,,,thank you.It works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top