Change the value of variable in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change the value of variable in a file
# 1  
Old 01-18-2013
Change the value of variable in a file

Hi Friends,

I have shell script file1.sh which has reference to enviornment file called

Content of filenev.sh

Code:
SKIP_FLAG=N
ORACLE_HOME=/u01/oracle/database

My requirement is to change the value of SKIP_FLAG to Y in filenv.sh from file1.sh. Could anyone please help me to do this.

After making the changes, content of fileenv.sh should like this:

Code:
SKIP_FLAG=Y
ORACLE_HOME=/u01/oracle/database

Thanks in advance.

Thanks,
Venkat

Last edited by Scott; 01-18-2013 at 11:55 AM.. Reason: Code tags
# 2  
Old 01-18-2013
You could re-write the file with:-
Code:
grep -v "^SKIP_FLAG=" $environment_file > /tmp/env_file.tmp
(cat /tmp/env_file.tmp ; echo "SKIP_FLAG=Y" ) > $environment_file
rm /tmp/env_file.tmp

Does that help?

You could edit it with sed of vi too, such as:-
Code:
echo ":%s /^SKIP_FLAG=N/SKIP_FLAG=Y/\n:wq" | vi $environment_file >/dev/null


I hope that these give you a start.

Robin
Liverpool/Blackburn
UK
# 3  
Old 01-18-2013
Thanks alot for quick help. It helped.

Thanks,
Venkat
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Change Param File Variable Test Mode Value

First two days of shell scripting... I've looked at awk/sed and man sed only to get off into the weeds of complexity that may not be needed here... hints for awk or sed or other method to magically change the bolded item below? Nutshell: HFTST=Y #test mode = true to false & back again so... (0 Replies)
Discussion started by: JeffPGMT
0 Replies

2. UNIX for Dummies Questions & Answers

Change variable value

I have big XML which i want to change all VERSIONNUMBER equal to 1,in existing file values of VERSIONNUMBER will be different as below now i want to change all VERSIONNUMBER values qual to 1.Please help me which will convert versionnumber values. <SHORTCUT OBJECTSUBTYPE ="" OBJECTTYPE ... (5 Replies)
Discussion started by: katakamvivek
5 Replies

3. UNIX for Dummies Questions & Answers

Change Date in Variable

I am hoping someone can help me with this issue. I am extracting a date from a file that is in DD/MM/YYYY format using... expiry_date=`echo ${line}| awk -F, '{ print $4 }' | tr -d '\r'` What I need to do is amend the value so instead of getting 30/12/2016 I end up with 12/30/2016. I have... (11 Replies)
Discussion started by: theref
11 Replies

4. Shell Programming and Scripting

I can't change the value of my variable!

I made this HEADMAKER variable to pull the header from the first file in the loop, but then to stop so it doesn't override the file with later loops. However, I CANNOT get it to reassign the value of my variable away from "FIRST". I have also tried it with 1 and 0, and with and without quotes and... (3 Replies)
Discussion started by: crankymonkey
3 Replies

5. Shell Programming and Scripting

Change Variable Value from Multiple Scripts and Use these Variable

Hi to All, Please find below details. file_config.config export file1_status="SUCCESS" export file2_status="SUCCESS" file_one.sh I am calling another two shell script from these script. I need to pass individual two script status (If it's "FAILED") to file_main.sh. file_main.sh I... (2 Replies)
Discussion started by: div_Neev
2 Replies

6. Shell Programming and Scripting

Change the filename variable value

Hi guys, I have a variable where i am storing the filename (with full path). I just need the value before ".txt". But instead of getting the filename i am getting the contents of the filename. FileName=/appl/data/Input/US/Test.txt a=`awk -F"." '{print $1}' ${FileName}` echo $a... (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

8. Shell Programming and Scripting

Change only the name of a variable

if I have a variable named z inside a java file, is there any way to globally change the name of the variable and all its occurences as a variable? (but not any other z that is not part of that variable name) (3 Replies)
Discussion started by: lydiaflamp
3 Replies

9. Shell Programming and Scripting

how to change the variable in the file

Hi all, I have problem regarding how to change the quantity in the file. I will explain you by an example. I have one file whose name is sample. The content of file are as follows: sample ----------------------------------------------------------- 1 334 3562 2345 5324 85657 75666 845 ... (0 Replies)
Discussion started by: Aniket
0 Replies

10. Shell Programming and Scripting

Pivot variable record length file and change delimiter

Hi experts. I got a file (500mb max) and need to pivot it (loading into ORCL) and change BLANK delimiter to PIPE |. Sometimes there are multipel BLANKS (as a particular value may be BLANK, or simply two BLANKS instead of one BLANK). thanks for your input! Cheers, Layout... (3 Replies)
Discussion started by: thomasr
3 Replies
Login or Register to Ask a Question