• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 755
  • Last Modified:

Debian SED command, Multiple line search and replace

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:
anonymous_enable=YES
local_enable=NO      **needs to be yes
write_enable=YES     **need to comment this out with #
0
LeviDaily
Asked:
LeviDaily
1 Solution
 
farzanjCommented:
Try:

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 ...
0
 
LeviDailyAuthor Commented:
Thanks, that works!!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now