Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Replace string in a file.

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago
ghettochild2600 ghettochild2600 is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 14 July 2017, 12:45 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 25 July 2017, 5:19 PM EDT
Location: Aachen, Germany
Posts: 11,063
Thanks: 284
Thanked 3,409 Times in 3,139 Posts
Use awk with an interim temp file.
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
shamrock shamrock is offline Forum Advisor  
Registered User
 
Join Date: Oct 2007
Last Activity: 10 July 2017, 10:43 AM EDT
Location: USA
Posts: 1,599
Thanks: 36
Thanked 157 Times in 148 Posts
Can you post what you've tried to solve this...
    #4  
Old Unix and Linux 1 Week Ago
ghettochild2600 ghettochild2600 is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 14 July 2017, 12:45 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I'm quite new to all this so some of my syntax is probably incorrect.


Code:
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>


Moderator's Comments:
Replace string in a file. Please use CODE tags as required by forum rules!

Last edited by RudiC; 1 Week Ago at 03:47 AM.. Reason: Added CODE tags.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace string in XML file with awk/sed with string from another cozzin Shell Programming and Scripting 9 02-15-2016 02:38 PM
Search for a string,delete the line and replace with new string in a file Pradhikshan UNIX for Dummies Questions & Answers 10 09-29-2015 04:45 AM
replace (sed?) a string in file with multiple lines (string) from variable jforce Shell Programming and Scripting 2 09-15-2011 10:10 AM
replace (sed?) a single line/string in file with multiple lines (string) from another file?? tuathan Shell Programming and Scripting 5 04-20-2011 12:16 AM
Using sed to replace a string in file with a string in a variable that contains spaces vivelafete Shell Programming and Scripting 2 11-24-2009 08:43 AM



All times are GMT -4. The time now is 08:41 PM.