Script to modify a line in text file

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


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?

Question by:yongsing
    LVL 18

    Accepted Solution

    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

    LVL 5

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (, discussed installing the Solaris Operating S…
    Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Video by: Phil
    This video goes over how to configure and start a jail in FreeBSD.  This video is meant to supplement the article included with this course.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now