Hi,
Variable=MKT1,MKT2,MKT3 and so on
i am trying to seperate MKT1,MKT2,MKT3 and store each in a variable.
the values in variable1 may vary. I am using bash
Hi,
Variable=MKT1,MKT2,MKT3 and so on
i am trying to seperate MKT1,MKT2,MKT3 and store each in a variable.
the values in variable1 may vary. I am using bash
Hi,
store them in var1, var2, var3 ... ok?
#!/bin/bash
Variable=MKT1,MKT2,MKT3
IFS=','
i=1
for j in ${Variable[@]}
do
eval var$i=$j
i=`expr $i + 1`
done
IFS=,
read -r variable1 variable2 variable3 <<< "$variable"
You'll need to set IFS to a comma in order to split the variable though:
IFS=, read variable1 variable2 variable3 <<< "$variable"
Thak you all for the wonderful input. It sings like a bird. But here comes the major problem.
Whenever i use IFS in my script, sqlplus doesnot run and throws me an error saying that no such file or directory.
I i remove IFS, sqlplus runs without any problem.
So i was wondering if there is any other way like awk or anything else, however bad or long programming it may be...thanks
Try unsetting IFS after you've used it:
IFS=, read variable1 variable2 variable3 <<< "$variable" ; unset IFS
Or use parameter substitution and array:
#!/bin/bash
Variable=MKT1,MKT2,MKT3
I=0
for T in ${Variable//,/ }
do
(( I++ ))
ARR[$I]="$T"
done
I=0
while [ $I -lt ${#ARR[@]} ]
do
(( I++ ))
echo ${ARR[$I]}
done
Thanks. Unsetting worked
Of course, true CSV can have embedded comma ',' and line breaks quoted within ". Make sure your data is 'well behaved' or use a more sophisticated tool (even MS Access was broken for many versions, I guess since it came from MS Excel, which was from one co. MS bought, and MS Access was from another). True CSV can also have " escaped as "".