Edit a config file using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edit a config file using shell script
# 1  
Old 04-30-2008
Edit a config file using shell script

I need to edit a config file using shell script. i.e., Search with the 'key' string and edit the 'value'.

For eg: below is what I have in the config file "configfile.cfg".

Key1=OldValue1
Key2=OldValue2

I want to search for "Key1" and change "OldValue1" to "NewValue1"

Thanks for your help.
# 2  
Old 04-30-2008
If you want to replace one key in one file you can do it with vi or is this homework?

Regards
# 3  
Old 04-30-2008
I want to do it in around 100 files - using shell script or a command. Not manually.
# 4  
Old 04-30-2008
hope this hepls you

sed -e 's/\(key1\=\)\(Old\)\(value1\)/\1New\2/g' filename

please iterate this in you shell programs for the key1 values and old value for each file.
# 5  
Old 04-30-2008
Edit: had that tab open for a while - chappidi_pradee gave a better solution
# 6  
Old 05-01-2008
Quote:
Originally Posted by chappidi_pradee
hope this hepls you

sed -e 's/\(key1\=\)\(Old\)\(value1\)/\1New\2/g' filename

please iterate this in you shell programs for the key1 values and old value for each file.
Thanks pradee.

Will this work for the below cases?

#This is a comment. YesNoFlag = No means it will not print
YesNoFlag = No

And I need to change No to Yes
# 7  
Old 05-01-2008
i think the script that i posted will not work for the example that you mentioend becasue there should not be any spaces between the equal to sign (=).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Open and edit a file using a shell script

Hello Folks, I have a file named as date.dat present at /tmp/abc location which has following data - 20161030,20161031,20161101 I need to remove this line and replace it with something like below - $param1,$param2,$param3 Param1, Param2 and param3 stores the date based on some calculation in... (1 Reply)
Discussion started by: ektubbe
1 Replies

2. Homework & Coursework Questions

Edit the file in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to automate hadoop installation procedure using shell script. It involves go to perticular directory... (3 Replies)
Discussion started by: Abdul Navaz
3 Replies

3. Shell Programming and Scripting

Automating using shell script : edit the file in a directory

I am trying to automate hadoop installation procedure using shell script. It involves go to perticular directory and add some more lines to the file /etc/sysctl.conf. How this can be done? Regards Navaz (1 Reply)
Discussion started by: Abdul Navaz
1 Replies

4. Shell Programming and Scripting

shell script to edit a file

i have a file called number which contains data as 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 0 1 2 3 4 needed a shell script to print the output as 1 7 7 1 4 and (2 Replies)
Discussion started by: jacky29
2 Replies

5. Shell Programming and Scripting

Shell script to edit a file

Hello, I have a big file in wich I would like to rename inside this exactly the string '_ME' and not rename in case we have 'ABC_MELANGE'. Is there a way to do it by using a shell script? Any tip will be apreciated. The file is like described bellow, after using command more filename : ... (3 Replies)
Discussion started by: Titas
3 Replies

6. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

7. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies

8. Shell Programming and Scripting

Edit hibernate config file

I'd like to use a shell script to edit the params in my hibernate.cfg.xml file. I need to substitute the database info(user name, password,url) Here is a look at it: <hibernate-configuration> <session-factory name=""> <property... (1 Reply)
Discussion started by: mc1392
1 Replies

9. Shell Programming and Scripting

shell script to edit the content of a file

Hi I need some help using shell script to edit a file. My original file has the following format: /txt/email/myemail.txt /txt/email/myemail2.txt /pdf/email/myemail.pdf /pdf/email/myemail2.pdf /doc/email/myemail.doc /doc/email/myemail2.doc I need to read each line. If the path is... (3 Replies)
Discussion started by: tiger99
3 Replies

10. AIX

How to edit txt file by shell script?

What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file (delete the lines) directly, as new lines may be added to the text file during this period. Can AIX do this ? # cat text 1:line1 2:line2... (3 Replies)
Discussion started by: dupeng
3 Replies
Login or Register to Ask a Question