Assign value to a variable in a parameter file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assign value to a variable in a parameter file
# 1  
Old 06-22-2005
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
EDW_User_Parm=t449206
FTP_Path_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM/ftp/
FTP_User_Parm=t449207
FTP_Password_Parm=Magdog,123
Date_Run_Parm=06042005
Sequence_ID_Parm=1
Daily_Sequence_Parm=1
ParameterFileParm="nothing"
Send_FTP_Parm=Y


What i should do is i need to write a script which should search for systemtime (based on the time we run) and if it is less than 12'0 clock then From_Date_Parm should be replaced with sysdate - 1 (2005-06-20) and To_Date_Parm as sysdate (2005-06-21) else if it is greater than 12 and less than 24 then From_Date_Parm = sysdate (2005-06-21)

How can i change the appropriate values using script.
I am new to unix and i want the code which does the corresponding job.

Thanks in advance.

cheers,
gops
# 2  
Old 06-22-2005
You can do it as,

#!/bin/sh
# Hour check script

if [[ $(date +'%H') -lt 12 ]]
then

perl -pi -e 's/^From_Date_Parm.*$/From_Date_Parm=sysdate - 1 (2005-06-20)/g' TransactionParams
perl -pi -e 's/^To_Date_Parm.*$/To_Date_Parm=sysdate (2005-06-21)/g' TransactionParams

elif [[ $(date +'%H') -gt 12 && $(date +'%H') -lt 24 ]]
then

perl -pi -e 's/^From_Date_Parm.*$/sysdate (2005-06-21)/g' TransactionParams

fi

hth.
# 3  
Old 06-22-2005
Hi Muthukumar,

Thanks for your prompt reply.

if [[ $(date +'%H') -lt 12 ]]
then

perl -pi -e 's/^From_Date_Parm.*$/From_Date_Parm=sysdate - 1 (2005-06-20)/g' TransactionParams
perl -pi -e 's/^To_Date_Parm.*$/To_Date_Parm=sysdate (2005-06-21)/g' TransactionParams

elif [[ $(date +'%H') -gt 12 && $(date +'%H') -lt 24 ]]
then

perl -pi -e 's/^From_Date_Parm.*$/sysdate (2005-06-21)/g' TransactionParams

fi

I dont want the number to be hardcoded like 2005-06-20 and 2005-06-21 as in your script.
It should pick up from systemdate and convert that into appropriate format.
By the way can i use perl scripts in Unix ? (I am a novice to unix and so I am raising such questions). Expecting earlier reply.

cheers,
gopskrish
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assign variable value from file to another with the same name

Hi All, I need to read two config files in a shell script. In that I need to assign a value from one config file to another. I 'm using bash. config_env.txt prefix=tab_ config_properties.txt table_name=${prefix}account So, when I read these two files in a shell script, I need... (6 Replies)
Discussion started by: shash
6 Replies

2. UNIX for Dummies Questions & Answers

Assign line from file to variable

Hi, I am new to shell scripting. Need help with the below requirement. I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table. For E.g. file test.sql has below error: ORA-01017:... (3 Replies)
Discussion started by: ricsharm
3 Replies

3. Shell Programming and Scripting

Assign a variable to number of lines in a file

Hello Gurus, Here is my requirement. I need to find the number of lines in a file and need to assign it to a variable. This is what I did and not wroking. #!/bin/ksh set -xv Src_Path=/mac/dev/Generic/SrcFiles Src_Count=wc -l ${Src_Path}/FILE_JUNE.txt Count_file = $Src_Count | awk -F... (2 Replies)
Discussion started by: thummi9090
2 Replies

4. Shell Programming and Scripting

How can we assign value to an array variable from an external file?

is it possible to assign value to an array variable from an external file?? if yes then how?? I am using below code but its not working. #!bin/bash myarray < file_name echo ${mayarray} (6 Replies)
Discussion started by: mukulverma2408
6 Replies

5. Shell Programming and Scripting

How to assign a shell variable to a NUMBER parameter in pl/sql?

I have the below script running for generating file from PL/SQL stored procedure. I need to declare a shell variable and then pass this to sqlplus command to pass the same as a INPUT parameter for the stored procedure. Please help to do this. #!/bin/sh minlimit=0 maxlimit=10 size=100 while... (0 Replies)
Discussion started by: vel4ever
0 Replies

6. Programming

Can't assign struct variable in header file

Hi guys. I have a header file including a structure like this: typedef struct { int index = -1; stack_node *head; } stack; But when compiling with cc it shows error at the assignment line (int index = -1): error: expected ‘:', ‘,', ‘;', ‘}' or ‘__attribute__' before ‘=' token... (1 Reply)
Discussion started by: majid.merkava
1 Replies

7. UNIX for Dummies Questions & Answers

How to assign the content of a file to a variable?

Hi all, I have a problem here. I have a file and let we take the content of the file is just '32' (only a numeric value in that file). Now I need to assign this numeric value ( value in that file) to a variable. Is that possible? If so, can you plz advice me on this? Thanks in... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

8. Shell Programming and Scripting

how to check a word in a file and assign to a variable

Hi; I'm a newbie in UNIX, would appreciate for the help. I have a unix oracle script (lets call it orcl.sh) The scripts does a login via sqlplus and does some DDL. The orcl.sh script spool the output of the DDL into orcl.log The orcl.sh is executed via another script call A.sh. It is call... (1 Reply)
Discussion started by: hippo2020
1 Replies

9. UNIX for Dummies Questions & Answers

search file for word, then assign to variable

Hi all, Trying to search a file for one word only, then assign that word to a variable. Not sure if this is a grep or awk (or either) function. Should be a simple operation. Example: This file contains the string "COMPLETE". I would like to pull that word out and assign it to a... (2 Replies)
Discussion started by: dejit
2 Replies

10. UNIX for Dummies Questions & Answers

How to Read a config file and Assign to Variable

I have removeConfig file, it contains the dir paths for removing. I need to read line by line and assign to variable. any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question