Reading a variable from parameter file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a variable from parameter file
# 1  
Old 11-23-2009
Reading a variable from parameter file

HI all,

I have a parameter file with entries like

$$Name =Abhinav
$$CUTOFF_DATE = 11/11/2209

I am reading a variable from this file using a awk command like :

var2=`awk -F"[=]" "/CUTOFF_DATE/{f=$1;}{print f;}" InputFIleName`

but facing an error like

awk: cmd. line:1: /CUTOFF_DATE/{f=;}{print f;}
awk: cmd. line:1: ^ parse error
:

Please help

---------- Post updated at 11:33 AM ---------- Previous update was at 11:24 AM ----------

on changing line to

var2=`awk -F"[=]" "/CUTOFF_DATE/{print $1;}" Gdmp_Interface.prm`

i get complete line $$CUTOFF_DATE = 11/11/2209
as output
# 2  
Old 11-23-2009
wrong delimiter

hello buddy,
your delimiter should be " = " and not "=" (note the spaces)
so your one liner comes close to
var2=`awk -F"[ = ]" '/CUTOFF_DATE/{f=$1;}{print f;}' InputFIleName`
here $1=CUT_OFF_DATE
and $2=11/11/2209
assuming you want to print the value then s/$1/$2 in the above one liner
# 3  
Old 11-23-2009
shell sites

what exactly do you mean by shell sites?
# 4  
Old 11-23-2009
You have to use single quotes otherwise $1 gets interpreted by the shell. E.g.
Code:
var2="$(awk -F'[= ]*' '/CUTOFF_DATE/{print $2}' InputFIleName)"



---------- Post updated at 00:56 ---------- Previous update was at 00:15 ----------

How about:
Code:
while IFS='= ' read var param; do
 eval ${var#\$\$}=\"$param\"
done<InputFIleName

Code:
$> echo $Name
Abhinav
$> echo $CUTOFF_DATE
11/11/2209


Last edited by Scrutinizer; 11-23-2009 at 07:42 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Identify the Parameter variable file

Hi I am trying to understand a shell scipt file ( .ksh file ) . In the shell script we are referring a variable . Example : SessLogs=$STAFF_MSTR_DIR/staff_dtls There are no references in the shell script from where the variable "$STAFF_MSTR_DIR" is being read from . Could anyone... (2 Replies)
Discussion started by: Sudheer Maddula
2 Replies

2. Shell Programming and Scripting

To call Oracle procedure by reading parameter file in UNIX

hi Guys, is there a way to pass parameter into oracle store procedure by reading date range in file and increment accordingly. Something like this file.txt 01-JAN-2015 03-JAN-2015 sqlplus -s user/pwd@DB execute TEST( to_date( '01-JAN-2015, 'dd.mm.yyyy' ), to_date( '03-JAN-2015', ... (1 Reply)
Discussion started by: rohit_shinez
1 Replies

3. Shell Programming and Scripting

Reading from a file and storing it in a variable

Hi folks, I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it. My file is 1.txt and its contents are VERSION=5.6 UPDATE=4 I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies

4. Shell Programming and Scripting

reading variable value from a file

Hello, I need to read a variable value from script. Below is the scenario I am reading a value from an external file say a.txt a.txt: Jan Feb Mar I need the corresponding value of the months in in numerics such as Jan -->1, Feb-->2 etc. I have this mapping in another file... (1 Reply)
Discussion started by: aixjadoo
1 Replies

5. UNIX for Dummies Questions & Answers

Reading from a file(passing the file as input parameter)

hi I have a shell script say primary.sh . There is a file called params my scenario is primary.sh should read all the values and echo it for example i should pass like $primary.sh params output would be Abc ... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

6. UNIX for Dummies Questions & Answers

Reading a variable from file

Hi, I have a situation where I need to read a variable from another file. But the problem is that the variable in the other file is starting with $. E.g. file1: $var1=out temp_ss.sh: . file1 echo "Print : $var1" It works fine if the file1 is having var1=out (note that it is... (6 Replies)
Discussion started by: shash
6 Replies

7. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

8. Shell Programming and Scripting

Reading a Parameter File

Hi, I need to read the parameters from a file and assign them to Global variables. I need to read a specific parameter value every time and pass it to the other script. Suppose i have a parameter file like PARAM.txt PAR1= VAL1 PAR2= VAL2 PAR3= VAL3 I want to read PAR2 file and in the... (1 Reply)
Discussion started by: Raamc
1 Replies

9. Shell Programming and Scripting

reading the parameter from another file

I have a script where 3 parametrs are passed to it and it creates the file for each site form a template. If i want to get the 3rd parameter (which is the site) passed to the script to come from another file how I can change the script tp acheive it? Here is my script: what i have in the... (15 Replies)
Discussion started by: dsravan
15 Replies

10. Shell Programming and Scripting

Assign value to a variable in a parameter file

Hi, I have a parameter file and it contains following items $ cat TransactionParams From_Date_Parm=2005-02-25 To_Date_Parm=2005-05-25 Extract_Root_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM Extract_Type_Parm=Transaction EDW_Database_Parm=hdw_erks... (2 Replies)
Discussion started by: gopskrish
2 Replies
Login or Register to Ask a Question