How to separate a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to separate a variable
# 1  
Old 11-01-2004
Data How to separate a variable

Hi,
This is what happened after I came back from vacation: I don't remember how to do some simple things anymore.

I have a variable being passed in Kshell script. I only know the variable is like string: "str1 str2 str3 ....", and they are separated with blank spaces. I need to separate each field to do some data processing. Does anyone have some ideas?


THANKS for the help!

Last edited by whatisthis; 11-02-2004 at 10:14 AM..
# 2  
Old 11-01-2004
Try this ...

#!/usr/bin/ksh

while test $# -ne 0
do
echo $1
shift
done
# 3  
Old 11-02-2004
Variable is not passed through command

That's pretty good thought if my variable is passed through command line.
But unfortunately my variable is not passed by the command line.
It's the variable passed by read command.
++++++++++++++++++++
# GET INTERVIEWER LIST
/usr/ucb/echo "Enter interviewer numbers seperated by blank or leave blank for a
ll interviewers"
/usr/ucb/echo -n "ENTER: "

read intvw

++++++++++++++++++
?
# 4  
Old 11-02-2004
Code:
for foo in $intvw
do
    echo $foo
    # do something with $foo
done

EDIT:

For info - you could use a method similar to bhargav
Code:
#!/bin/sh

echo "Enter space-seperated stuff..."
read intvw

set -- $intvw

while [ "$#" -ne "0" ]
do
   echo "$1"
   shift
done

Cheers
ZB

Last edited by zazzybob; 11-02-2004 at 11:29 AM..
# 5  
Old 11-02-2004
one more alternative :



echo "enter input: "
read abc

for i in `echo $abc`
do
echo $i
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar with variable date in separate shell

Hi, I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause. testno=1; date=20171128; DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"' ... (5 Replies)
Discussion started by: pradyumnajpn10
5 Replies

2. Shell Programming and Scripting

Separate variable value

Friends, I have the following problem var=30|500; I need to keep those values in the variable other unique pattern that I have is | so should be var2=30; var3=500; I tried to use my split does not work Example failed var2=split("|",$var); var3=split("|",$var); (4 Replies)
Discussion started by: tricampeon81
4 Replies

3. Shell Programming and Scripting

Separate a hash variable into 2 parts in Perl

Dear Perl users/experts, Could somebody help me how to solve my problem, I have a hash variable that I want to convert into dot file (graphviz). I know how to convert it to dot file but I need some modification on the output of the hash variable before convert it to dot file. Eeach key of... (1 Reply)
Discussion started by: askari
1 Replies

4. Shell Programming and Scripting

Separate fields

awk 'NF==2{s=$1;next}{$(NF+1)=s}1' sort.txt > output.txt A_16_P32713632 chr10 90695750 90695810 ACTA2 A_16_P32713635 chr10 90696573 90696633 ACTA2 A_16_P32713680 chr10 90697419 90697479 ACTA2 The command above outputs the data as a string separated by a space in 1 field. I can not... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

How to separate a statement based on some delimiter and store each field in a variable?

Hi, Variable1 = MKT1,MKT2,MKT3,MKT4 Now i want to store each of these value seperated by comma to a array and access each of the values. Also find out number of such values seperated by comma. Variable1 can have any number of values seperated by comma. Thanks :) (3 Replies)
Discussion started by: arghadeep adity
3 Replies

6. UNIX for Dummies Questions & Answers

Want to separate one column

I have one command which provide following output related to file system and disk space utilization Filesystem kbytes used avail %used Mounted on /dev/lvol3 131072 73407 54088 58% / /abc/lvol1 59797 30314 2350300 ... (8 Replies)
Discussion started by: Nakul_sh
8 Replies

7. Shell Programming and Scripting

Awk variable in a separate file

Hi all, I have a requirement to put all the varibles used in an awk command in a separate file. This is because i have arround 100 variables used in an awk command. So i want to put all the variables used for the awk command in a separate file. Please help me on this. Thanks in adv. (6 Replies)
Discussion started by: gani_85
6 Replies

8. Shell Programming and Scripting

Trying to take a string and break each letter into a separate variable

I am trying to make a script that takes a word and each letter up and turns it into a separate variable. My code currently does not work but I feel I just need to tweak one thing that I am unsure of. (ex: if forum was typed in letter1=f; letter2=o; letter3=r;...) Thank you count=1; ... (7 Replies)
Discussion started by: crimputt
7 Replies

9. Shell Programming and Scripting

Separate fields

Hi everyone! I have a field like that: I need to keep I don't know how to use the Capital character like a separator and how to keep only this one... I guess sed could do something like that... Thanks;) (3 Replies)
Discussion started by: Castelior
3 Replies

10. Shell Programming and Scripting

Cant separate variables

Hey guys, new problem....im not being able to seperate variables. the code runs like this... OPTIONS=$(awk '{print $2}' /etc/fstab} a=$(zenity --list --text "Mount points selection" --radiolist --column "choice" --column "mountpt" FALSE $OPTIONS); echo $a Note: the result i get is that... (2 Replies)
Discussion started by: dplate07
2 Replies
Login or Register to Ask a Question