SED practice, some SED common methods

1. Copy the /etc/rc.d/rc.local file to the /tmp directory, and copy the
Add # at the beginning of lines that start with at least one blank character.
sed -ri’s/^ +/#/g’ rc.local
2. Copy /boot/grub2/grub.conf to the /tmp directory and delete the blank characters at the beginning of the line in the /tmp/grub.conf file.
#sed -r’s/(^ +)(.*)//g’ /tmp/grub.conf ++++ +> Only delete blank characters in lines with blank characters at the beginning
sed -nr’s/^ +//pg’ /tmp/grub.conf +++++> Delete all blank characters at the beginning of the line
3. Delete the # beginning with # in the /tmp/rc.local t file, and # And white space characters in lines followed by at least one white space character.
sed -r -e’s/#(.*)//g’ -e’s/ +(.*)//g’ rc.local < /em>
4. Add # to the beginning of the first three lines in the /tmp/grub.conf file.
sed -ri ‘1,3 s/(.*)/#/g’ rc.local
5. Set all enabled=0 or gpgcheck in the /etc/yum.repos.d/CentOS-Media.repo (just find one) file =0
The last 0 is changed to 1
sed -nr ‘/enabled|gpgcheck/ s/.*=(.*)/1/gp’ local.repo
6, every 4 Perform a backup of the /etc directory once every hour, back up to the /backup directory, and the saved directory name is like etc-201504020202.
* */4 * * * cp /etc/* /backup/etc-$(date +%Y%m%d%H%M )
7, every week 2, 4, 6 backup /var/log/messages file to /backup/messages_logs/ directory, The saved file name is like messages-20150402.
crontab -e

* * * * 2,4,6 cp /var/log/messages /backup/messages_logs/messages-$(date +%Y%m%d)

8. Get all the information starting with S in the current system /proc/meminfo file to the /stats/memory.txt file every two hours every day.
crontab -e
* */2 * * * sed- nr’/^S.*/p’ /proc/meminfo> /stats/memory.txt
9. Work day During the time, the echo “howdy” is executed every two hours.
* * * * 1-5 echo “howday”
10. Create directory /tmp./testdir-current date and time
mkdir testdir-$(date +%F-% H:%M:%S)
12. Display the user name of the user on the even-numbered line in the /etc/passwd file.
sed -n ‘2~2p’ /etc/passwd

1. Copy the /etc/rc.d/rc.local file to the /tmp directory, and copy the
Add # at the beginning of lines that start with at least one blank character.

sed -ri’s/^ +/#/g’ rc.local

2. Copy /boot/grub2/grub.conf to the /tmp directory and delete the blank characters at the beginning of the line in the /tmp/grub.conf file.
#sed -r’s/(^ +)(.*)//g’ /tmp/grub.conf ++++ +> Only delete blank characters in lines with blank characters at the beginning
sed -nr’s/^ +//pg’ /tmp/grub.conf +++++> Delete all blank characters at the beginning of the line
3. Delete the # beginning with # in the /tmp/rc.local t file, and # And white space characters in lines followed by at least one white space character.
sed -r -e’s/#(.*)//g’ -e’s/ +(.*)//g’ rc.local < /em>

4. Add # to the beginning of the first three lines in the /tmp/grub.conf file.

sed -ri ‘1,3 s/(.*)/#/g’ rc.local

5. Set all enabled=0 or gpgcheck in the /etc/yum.repos.d/CentOS-Media.repo (just find one) file =0
The last 0 is changed to 1
sed -nr ‘/enabled|gpgcheck/ s/.*=(.*)/1/gp’ local.repo

6, every 4 Perform a backup of the /etc directory once every hour, back up to the /backup directory, and the saved directory name is like etc-201504020202.
* */4 * * * cp /etc/* /backup/etc-$(date +%Y%m%d%H%M )

7, every week 2, 4, 6 backup /var/log/messages file to /backup/messages_logs/ directory, The saved file name is like messages-20150402.
crontab -e

* * * * 2,4,6 cp /var/log/messages /backup/messages_logs/messages-$(date +%Y%m%d)

8. Get all the information starting with S in the current system /proc/meminfo file to the /stats/memory.txt file every two hours every day.
crontab -e
* */2 * * * sed- nr’/^S.*/p’ /proc/meminfo> /stats/memory.txt

9. Work day During the time, the echo “howdy” is executed every two hours.
* * * * 1-5 echo “howday”

10. Create directory /tmp./testdir-current date and time

mkdir testdir-$(date +%F-% H:%M:%S)

12. Display the user name of the user on the even-numbered line in the /etc/passwd file.
sed -n ‘2~2p‘ /etc/passwd

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5132 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.