how many are these ..?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how many are these ..?
# 1  
Old 10-20-2009
MySQL how many are these ..?

Say

I have a variable set as following

A='IND,US,UK,AUS,NZ'

now i want to know how many words are present in this string ?

In above example,i can see 5 country names set to variable A.

How can i find out that variable A is set to a string containing 5 names(items...whatever) in it?

I am looking for the count....not the length...& all the strings i would refer here,they are always comma separated...

Regards
Abhi

Last edited by ak835; 10-20-2009 at 11:22 AM..
# 2  
Old 10-20-2009
one way in bash
Code:
$ A='IND,US,UK,AUS,NZ'
$ read -a arr <<<${A//,/ }
$ echo "word count: ${#arr[@]}"
word count: 5

# 3  
Old 10-20-2009
MySQL

okay...thanks !!

this one is also working... !!

Code:
bash-3.00$ A='IND,US,UK,AUS,NZ'
bash-3.00$ echo $A|awk -F',' '{ print NF }'
5


Regards
Abhi
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question