Replace string in a file.

Hopefully my request is a simple one. I need to replace, rather remove the string </IfModule> from a file, tls.conf. As I have a script that adds a bunch of other lines including that one to the end of the file.

Use awk with an interim temp file.

Can you post what you've tried to solve this...

I'm quite new to all this so some of my syntax is probably incorrect.

sudo awk '{sub("</IfModule>", "TLSRequired off", $0); print}' /etc/proftpd/tlsBAK.conf

sed -i 's/</IfModule>/TLSRequired off/g' /etc/proftpd/tlsBAK.conf

sudo sed -i -e 's/\<\//IfModule/>/test/g' /etc/proftpd/tlsBAK.conf

sudo sed -i -e 's/^\/\/\"</IfModule>";/\"TLSRequired off";/' /etc/proftpd/tlsBAK.conf


sudo bash -c 'echo -e "\nTLSRequired off" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSProtocol TLSv1" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSRSACertificateFile /etc/webmin/miniserv.pem" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSRSACertificateKeyFile /etc/webmin/miniserv.pem" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSCipherSuite HIGH:!ADH:!AES256-SHA:!ECDHE-RSA-AES256-SHA384:!AES128-SHA:!DES-CBC3-SHA:!DES-CBC3-MD5:!IDEA-CBC-SHA:!RC4-MD5:!IDEA-CBC-MD5:!RC2-CBC-MD5:!MD5:!aNULL:!EDH:!AESGCM" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSVerifyClient off" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSRenegotiate ctrl 3600 data 512000 required off timeout 300" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSLog /var/log/proftpd/tls.log" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo "TLSOptions NoSessionReuseRequired" >> /etc/proftpd/tls.conf'
sudo bash -c 'echo -e "\n</IfModule>" >> /etc/proftpd/tls.conf'

</IfModule> is added at the end. Needs to delete the first instance as it is replaced.

# What file currently looks like

</IfModule>

# Added by script
TLSRequired off
TLSProtocol TLSv1
TLSRSACertificateFile /etc/webmin/miniserv.pem
TLSRSACertificateKeyFile /etc/webmin/miniserv.pem
TLSCipherSuite HIGH:!ADH:!AES256-SHA:!ECDHE-RSA-AES256-SHA384:!AES128-SHA:!DES-CBC3-SHA:!DES-CBC3-MD5:!IDEA-CBC-SHA:!RC4-MD5:!IDEA-CBC-MD5:!RC2-CBC-MD5:!MD5:!aNULL:!EDH:!AESGCM
TLSVerifyClient off
TLSRenegotiate ctrl 3600 data 512000 required off timeout 300
TLSLog /var/log/proftpd/tls.log
TLSOptions NoSessionReuseRequired

</IfModule>