parsing a string into variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing a string into variable
# 1  
Old 02-09-2006
parsing a string into variable

I know solution to this but I was wondering if its easier than what i think

I have to pass 20 parameters to a script, which of course is not working so I parsed $3 to be a pipe deliminated string

for instance below

a.ksh One Two Compa|Compb|Compc|compd|.............

Now i have to read $3 n parse and store the pipe deliminated value to a individual variable.

My theory was to parse it first and put it in a file and then read individual lines of file into a variable but i was wondering if there was easier way of doing this in one shot

your advice is as always helpful Smilie

Thanks
# 2  
Old 02-09-2006
Try this

Create an environment file for eg. environ.env which has all your required variables in it

export VAR1="var1"
export VAR2="var2"
export VAR3="var3"
export VAR4="var4"
export VAR5="var5"
export VAR6="var6"
export VAR7="var7"
export VAR8="var8"
export VAR9="var9"
export VAR10="var10"
export VAR11="var11"
export VAR12="var12"
export VAR13="var13"
export VAR14="var14"
export VAR15="var15"
export VAR16="var16"
export VAR17="var17"
export VAR18="var18"
export VAR19="var19"
export VAR20="var20"

Now in your shell script source this environment file

. environ.env


Then you can use the variables anytime in the shell without assigning them again.
# 3  
Old 02-09-2006
but the variables are passed by users and they r not fixed..

I'd also thought of that but..:-(
# 4  
Old 02-09-2006
*oops I meant parameters r passed by user and r not fixed
# 5  
Old 02-09-2006
Quote:
Originally Posted by Anubhav
I have to pass 20 parameters to a script, which of course is not working so I parsed $3 to be a pipe deliminated string
Why do you say "of course it is not working"? You can have as many parameters as you need, but remember to use {} above $9, e.g...
Code:
$ set a b c d e f g h i j k l m n o p q r s t u v w x y z
$ echo ${20}
t

# 6  
Old 02-10-2006
Thanx so much!!!

It worked..I almost had it working with getopts also

but this is cool I will remember this in future

Thanx so much
-Anu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check if string variable is a subset of another string variable

Below is my ksh shell script where I need to check if variable fileprops is a subset of $1 argument. echo "FILE PROPERTY: $fileprops" echo "PARAMETER3: $1" if ; then echo "We are Good. $line FILE is found to be INTACT !! " else echo... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

3. UNIX for Dummies Questions & Answers

Parsing a variable

Can someone help me? I have been looking in the archives as I am sure this is very simple to do, but I do not know. I have a variable which sometimes contains a file name and sometimes contains a fully qualified file name. I want to be able to separate the directory from the file name into 2... (3 Replies)
Discussion started by: CAGIRL
3 Replies

4. UNIX for Dummies Questions & Answers

Parsing String

Hi, I am trying to do the following in Linux: I have some text as follows: /home/user/backup/scripts/SDW/sql/backup.sql which needs to be parsed: to pick up "backup" So, pick up text after the last '/' until '.' from a string. Can someone please tell me how can I do that? ... (2 Replies)
Discussion started by: thinksys
2 Replies

5. Shell Programming and Scripting

String-parsing!

I need the perl solution for the following : $string="I LOVE INDIA" now, in a new string i need the first character of each word... that is string2 should be "ILN". (10 Replies)
Discussion started by: vijay_0209
10 Replies

6. Shell Programming and Scripting

parsing a variable

Hi, I want to get an input from user and parse the input. The legal characters allowed in the input are alnum(a-zA-Z0-0), . , - Also the first and las characters must be alnum only. e.g if the input is abc.ghh-sok.com then the script should return correct, and if the input is like... (2 Replies)
Discussion started by: g_rohit7
2 Replies

7. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

8. Programming

parsing string in c

how can i remove the special characters hi iam print the string variable . suppse: while(str!=NULL) printf("******* %s ********** %d ",str,strlen(str)); output as: ****srinu ******** 5 **** phani******** 63 ****srinu ******** 5 **** phani******** 63 so my problem is how can i... (3 Replies)
Discussion started by: phani_sree
3 Replies

9. Shell Programming and Scripting

Need help on parsing string

String example: /vmfs/volumes/46000471-71d7c414-8f74-0013210cddc3/gistst/gistst.vmx What I would like to do is create a variable and save gistst in it. I thought if I could create an array and split it by '/' then I could use the 4th array element or if they was a way to do a... (13 Replies)
Discussion started by: magnacrazy
13 Replies

10. Shell Programming and Scripting

Parsing a variable string

Hi all, I have a problem surfacing and I hope you all could help. What I have to do is take a input file and fill out a fax template from that file. The biggest problem I found was I have to parse the string "//FAX(faxnumber=555-5555;style="style1"; and on and on. The string can be in any... (5 Replies)
Discussion started by: pageld
5 Replies
Login or Register to Ask a Question