Lets take an example of simple nagios host config file.
Example file name : localhost.cfg
# for the local machine
# A host for the local machine
# Monitoring template
# Define a host for the local machine
define host{
        use                     linux-server                    
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }
Here I want to delete starting 3 lines of my file localhost.cfgto completely look like as
# Define a host for the local machine
define host{
        use                     linux-server                    
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }
Using sed to delete starting 3 lines of a file
cybeerkeeda@Linux-Maniac:~ sed -i -e "1,3d" localhost.cfg
sed -i : Here -i parameter will directly write the changes into the file.
I suggest to take a automatically take up backup during this comand.
cybeerkeeda@Linux-Maniac:~ sed -i.bak -e "1,3d" localhost.cfg
 Search more SED tutorials on the go here.

No comments:
Post a Comment