Nov 22, 2001 #1 pd123 Programmer May 22, 2001 48 GB Very new to this so bear with me. I have a variable in a shell script which I would like to split into 2 variables when a ',' is encountered. eg. var = "some stuff,more stuff" Into var1 = "some stuff" var2 = more stuff" Thanks.
Very new to this so bear with me. I have a variable in a shell script which I would like to split into 2 variables when a ',' is encountered. eg. var = "some stuff,more stuff" Into var1 = "some stuff" var2 = more stuff" Thanks.
Nov 22, 2001 #2 grega Programmer Feb 2, 2000 932 GB I've already answered this on the Solaris forum, but ... VAR1=$(echo $VAR | cut -d, -f1) VAR2=$(echo $VAR | cut -d, -f2) You could use awk as well, but this method is as good as any. Greg. Upvote 0 Downvote
I've already answered this on the Solaris forum, but ... VAR1=$(echo $VAR | cut -d, -f1) VAR2=$(echo $VAR | cut -d, -f2) You could use awk as well, but this method is as good as any. Greg.
Nov 22, 2001 Thread starter #3 pd123 Programmer May 22, 2001 48 GB I wasn't sure on the best place to post it. Thanks anyway. Upvote 0 Downvote
Nov 22, 2001 #4 gregor weertman Programmer Sep 29, 2000 195 NL IFS = Internal field separators. Default = " " var="some stuff,more stuff" IFS=, set $var echo $1 some stuff echo $2 more stuff IFS=" " Gregor.Weertman@mailcity.com Upvote 0 Downvote
IFS = Internal field separators. Default = " " var="some stuff,more stuff" IFS=, set $var echo $1 some stuff echo $2 more stuff IFS=" " Gregor.Weertman@mailcity.com
Nov 22, 2001 #5 aigles Technical User Sep 20, 2001 464 FR Another method with IFS var="first value,second value" ( IFS=, echo $var ) | read var1 var2 echo $var1 # => first value echo $var2 # => second value Jean Pierre. Upvote 0 Downvote
Another method with IFS var="first value,second value" ( IFS=, echo $var ) | read var1 var2 echo $var1 # => first value echo $var2 # => second value Jean Pierre.