Several skills of using sed

4 ways to #sed a commented line

#Insert # before this string of server 0.centos.pool.ntp.org instead of this line, so if this string is not at the beginning of this line, then # is inserted in the middle, and there is no comment Effect

sed -i 's/server 0.centos.pool.ntp.org/#&/' /etc/ntp.conf

 #Insert before the line matching server 1.centos.pool.ntp.org #

sed -i '/server 1.centos.pool.ntp.org/s/^/#/' /etc/ntp.conf

# Replace server 2.centos.pool.ntp.org iburst with #server 2.centos.pool.ntp.org iburst

sed -i 's/server 2.centos.pool.ntp.org iburst/#server 2.centos.pool.ntp.org iburst/' /etc/ntp.conf

#Only replace the first 'charly' with 'charly-->' , not the full text

sed -i '0,/charly/s//charly-->/' /build/web/webapps/latest/WEB-INF/applicationContext-job.xml

#Replace the one starting with server 3.centos.pool.ntp.org iburst ; & means to match any character (that is to say, unknown number, anything is fine)

sed -i 's/^server 3.centos.pool.ntp.org iburst/#&/' /etc/ntp.conf

 #Configure the upstream time server as the local ntpd Server server

sed -i '25a\server 10.0.13.100' /etc/ntp.conf

#Configuration allows the upstream time server to actively modify the local time

sed -i '26a\restrict 10.0.13.100 nomodify notrap noquery'  

 #sed uncomment line

sed -i 's/^#server0.centos.pool.ntp.orgiburstserver0.centos.pool.ntp.orgiburst/\1/' /etc/ntp.conf

sed -i 's/^#server1.centos.pool.ntp.orgiburstserver1.centos.pool.ntp.orgiburst/\1/' /etc/ntp.conf 

   The meaning of ##\1 is similar to the previous (bbb\) \1 is to copy the content of this position, if there is a second one for as long as \2 is to copy the content of the second position

sed -i 's/^#server 2.centos.pool.ntp.org iburst/server 2.centos.pool.ntp.org/' /etc/ntp.conf

sed -i 's/^#server3.centos.pool.ntp.orgiburstserver3.centos.pool.ntp.orgiburst/\1/' /etc/ntp.conf

Guess you like

Origin blog.csdn.net/baidu_41881646/article/details/130851906
sed