|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to parse file and assign parsed contents to variables?
.ksh newbie
![]() Could some please point me to some good help tools on how I can read in a file, and parse out content to assign to variables? Contents of Example file (misc_data.dat): warehouse,"/this/that" home,"/this2/that" node,"good" Basically, i want to read in the file and assign "this/that", "this2/that", and "good" to different variables. Is this possible? Last edited by bdg8255 : May 29th, 2007 at 10:56 AM. Reason: revise |
|
#2
|
|||
|
|||
|
Yes, very easily!
Try: Code:
awk -F\, '{print $2}' your_input_file
When you are happy it is producing what you want, then: Code:
myvar=$(awk -F\, '{print $2}' your_input_file)
That will, of course, put ALL the output into one variable. If you know what the 'first bit' of theline is going to be you can do Code:
mywharehouse=$(grep "^warehouse" your_input_file |awk -F\, '{print $2}')
or something similar
__________________
"I feel so miserable without you; it's almost like having you here" - Stephen Bishop |
|
#3
|
|||
|
|||
|
in bash
Code:
#!/bin/sh IFS=, while read var1 var2 do echo "$var1 , $var2" done < "file" |
|
#4
|
|||
|
|||
|
Thank you so much!
I really appreciate the help.
|
|
#5
|
|||
|
|||
|
Quote:
Code:
#!/bin/ksh while IFS=, read var1 var2 do echo "$var1 , $var2" done < "file" |
|
#6
|
|||
|
|||
|
I saw this thread from a search engine and registered on this website JUST because this solved a problem that I had been having for 3 days now, Thank you thank you thank you
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > How to parse file and assign parsed contents to variables? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|