Parsing and getting values of variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing and getting values of variables
# 1  
Old 08-01-2006
Parsing and getting values of variables

suppose i have a file value where it returns 3 values

a=1 b=2 c=4

when i run it.

i am using this file in my shell script. how do i parse and get the value of a b and c?
# 2  
Old 08-01-2006
Try something like this:
Code:
$ a=`echo "a=1 b=2 c=4" | awk '{print $1}' | cut -d= -f2`
$ echo $a
1

# 3  
Old 08-01-2006
Thanks so much
# 4  
Old 08-01-2006
Another way :
Code:
echo "a=1 b=2 c=3" > filename
eval $(<filename)

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file and setting to variables.

greetings all, I have a task right now that is somewhat stumping me, and I am not sure what the best approach is to take it. I have a text file that will contain something similar to the following: first1, other1 first2, other2 first3, other3 first4, other4 I have to generate an... (14 Replies)
Discussion started by: jeffs42885
14 Replies

2. Shell Programming and Scripting

Parsing fields into variables

A record contains 50 fields separated by "~". I need to assign each of these fields to different variables. Following is the shell script approach I tried. RECORD="FIELD1~FIELD2~FIELD3~FIELD4~FIELD5~...........~FIELD50" VAR1=$(echo ${RECORD} | cut -d"~" -f 1) VAR2=$(echo ${RECORD} | cut... (5 Replies)
Discussion started by: krishmaths
5 Replies

3. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

4. Shell Programming and Scripting

Parsing values

can anybody tell me why this code does not work? cat x1.ksh #!/bin/ksh set -x echo "|$#|" while do case $1 in --+() shift K=$1 ;; *) echo "Here I am" shift ;; (1 Reply)
Discussion started by: BeefStu
1 Replies

5. Shell Programming and Scripting

parsing values

I have a big file with the following format "57:24,A:1,B:5,C:7,D:10)" "42:24,A:2,B:6,C:4,D:5)" "45:34,A:1,B:7,C:5,D:6)" every row has the same characters. I want to parse out the values seen after each of the character followed by ':' into a tab delimited file of the following format ... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. Shell Programming and Scripting

parsing df column values

Hi all, I need to run df, and parse the value under column of "Mounted on" For instance, my df is Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 4881344 4106460 526924 89% / none 245164 220 244944 1% /dev... (6 Replies)
Discussion started by: peuceul
6 Replies

7. UNIX for Dummies Questions & Answers

Parsing alphanumeric variables

Hi All, I have files with a column which has values and ranges, for example colA colB ERD1 3456 ERD2 ERD3 4456 I want to have the following output colA colB colC ERD1 3456 3456 ERD2 526887 526890 ERD3 4456 4456 Being a newbie to... (2 Replies)
Discussion started by: alpesh
2 Replies

8. UNIX for Dummies Questions & Answers

Issue with parsing config variables

I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable. # Below RootDir is defined in windows RootDir="\\f01\var" # in unix script details="$RootDir/src|$RootDir/tgt" src=`echo $details|awk -F '|' '{print... (1 Reply)
Discussion started by: madhukalyan
1 Replies

9. Shell Programming and Scripting

Help parsing logs maybe with menu and variables?

I would like to parse through some logs looking for things like exception or failed (grep -i failed). Ideal would be if it were in a menu format so someone without unix ability could just choose option 1 2 or 3 etc. If I could pass the hostname to a variable also that would be awesome, so someone... (5 Replies)
Discussion started by: taekwondo
5 Replies

10. Shell Programming and Scripting

Perl: parsing variables

I have the following script: #!/usr/bin/perl -w @files = <*.csv>; foreach $file (@files) { open(FH, $file); my @dt = split(/_|.csv/, $file); while (<FH>) { chomp; print $dt . $dt . ",$_\n"; } close(FH); } This script reads in all csv files in the current directory... (2 Replies)
Discussion started by: figaro
2 Replies
Login or Register to Ask a Question