[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to modify a line in text file

Posted on 2006-03-29
2
Medium Priority
?
1,199 Views
Last Modified: 2013-12-27
I have a property file, and one of the line in it is like this:

...
useDDSAgent=true
...

I am writing a script to change the value of useDDSAgent to "false". It should be able to open the file, change the value, and save the file. How do I do that?

Thanks.
0
Comment
Question by:yongsing
2 Comments
 
LVL 18

Accepted Solution

by:
liddler earned 200 total points
ID: 16319955
sed can do the change, but outputs to a different file (you can't make sed overwirite the origina), so use mv to rename the file

sed -e 's/useDDSAgent=true/useDDSAgent=false/' myfile > myfile.tmp
mv myfile.tmp myfile

0
 
LVL 5

Expert Comment

by:devrick0
ID: 16320728
Also, depending on what version of sed you are running, there is also the -i option (only available in newer versions of sed).  With the -i option, you don't have to create any tmp file and perform moves after the fact.  The file gets modified in place.

So for example:
sed -i -e 's/useDDSAgent=true/useDDSAgent=false/' filename
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question