Debian SED command, Multiple line search and replace

Posted on 2012-08-14
Last Modified: 2012-08-14
I have a config file that I am trying to edit with sed. Currently I am searching one line and replacing and it is working, but I would like to search and replace multiple lines and I am not sure on the correct command.

sudo sed -e "s/anonymous_enable=YES/anonymous_enable=NO/g" /etc/vsftpdbackup.conf
*This above works great, but I have another line below that I need to replace.

The config file looks like this:
local_enable=NO      **needs to be yes
write_enable=YES     **need to comment this out with #
Question by:LeviDaily
    LVL 31

    Accepted Solution


    sudo sed "s/anonymous_enable=YES/anonymous_enable=NO/g;s/local_enable=NO/local_enable=YES/;s/^write_enable=/#&/" /etc/vsftpdbackup.conf

    Open in new window

    If you want to modify the file as well, use sudo sed -i ...
    LVL 2

    Author Closing Comment

    Thanks, that works!!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Extended attributes? 2 40
    Amazon EC2 Instance with EBS Block attached 1 40
    oracle query help 36 45
    Squid Authentication 7 12
    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now