i have srtring i.e. "NAME,CLASS,AGE" (length of string is not constant) and from this string i've extract each word delimited by "," (comma).
INPUT: "NAME,CLASS,AGE"
OUTPUT: NAME
CLASS
AGE
how can i do that?
i have tried some string manipulation function like index (echo `expr index $stringZ $var`) etc, but it seems sun solaries does not support that one.
i am using bash shell
please help, i'll appricate any kind of help.
There are several ways -
one is:
echo "$string"| IFS=, read a b c
echo $a
echo $b
echo $c
length of "string" is not fixed, it can contain any number of word like
"STD,CLASS,AGE,DEPT"
"STD,CLASS" etc
awk -F ',' '{ print "name " $1; print "Class" $2 }' and so on.
i don't know how many word it contains, i mean to say this "string" is fetched from database, now i don't know how many word there. Like some time it may contain only 2 word some time 7, meaning to say we don;t know how many word are there.
i think now you got my problem, still not then please let me know
Perhaps:
echo "$string" | tr ',' '\n'
If not, can you better explain what you want to achieve ?