I'm using 'sed' to modify config files.
Specifically, I'm using 'sed' to search lines with "</Direcotry>" and insert lines above it. My example command is as below (test.conf file contains multiple sections of <Directory ....>....</Directory>-
sudo sed –i.bak ‘/<\/Directory>/i \\t<Test1>\n\t\tThis is test1\n\t<\/Test1>’ test.conf
test.conf is customed conf file (see below) and -i.bak will create backup of original file so you can retry the command with.
This command works on my file but it also modify the commented section(s), how can I make the command to skip the commented lines (e.g. [#</Directory>] or [# </Directory>])?
You can grab any httpd.conf file with '<Directory ...> sections or create your own one like below -
<Directory /opt/test>
Some text
</Direcotry>
#<Directory /opt/test>
# Some text
#</Direcotry>
<Directory /opt/test>
Some text1
</Direcotry>
Expected result (after sed command works completely)
<Directory /opt/test>
Some text
<Test1>
This is test1
</Test1>
</Direcotry>
#<Directory /opt/test>
# Some text
#</Direcotry>
<Directory /opt/test>
Some text1
<Test1>
This is test1
</Test1>
</Direcotry>
Thanks!
Specifically, I'm using 'sed' to search lines with "</Direcotry>" and insert lines above it. My example command is as below (test.conf file contains multiple sections of <Directory ....>....</Directory>-
sudo sed –i.bak ‘/<\/Directory>/i \\t<Test1>\n\t\tThis is test1\n\t<\/Test1>’ test.conf
test.conf is customed conf file (see below) and -i.bak will create backup of original file so you can retry the command with.
This command works on my file but it also modify the commented section(s), how can I make the command to skip the commented lines (e.g. [#</Directory>] or [# </Directory>])?
You can grab any httpd.conf file with '<Directory ...> sections or create your own one like below -
<Directory /opt/test>
Some text
</Direcotry>
#<Directory /opt/test>
# Some text
#</Direcotry>
<Directory /opt/test>
Some text1
</Direcotry>
Expected result (after sed command works completely)
<Directory /opt/test>
Some text
<Test1>
This is test1
</Test1>
</Direcotry>
#<Directory /opt/test>
# Some text
#</Direcotry>
<Directory /opt/test>
Some text1
<Test1>
This is test1
</Test1>
</Direcotry>
Thanks!