1. Use the SED command to print out the IP address of the ifconfig ens33
Solution: (1) ifconfig Ens33 | Sed-n ' 2p ' | Sed ' s/.*inet//' | Sed ' s/netmask.*//'
(2) Ifconfig Ens33 | Sed-n ' 2p ' | Sed-r ' s/.*inet (. *) netmask.*/\1/'
(3) Ifconfig Ens33 | Sed-r-N ' 2s/.*inet (. *) netmask.*/\1/p '
2. Use the SED command to print out the system version
Solution: Sed-r-N ' s/.*release[[:space:]]* ([^.] +). */\1/p '/etc/centos-release
3, script title: Use SED to determine the version number if the version number is 7 in/etc/default/grub grub_cmdlinux_linux= "RHGB quiet" after the addition of xxxxx characters, if not exit does not execute
Solution: vim/root/bin/test/sedtest.sh
#!/bin/bash
banben= ' Sed-nr ' s/.*release[[:space:]]* ([^.] +). */\1/p '/etc/centos-release '
["$banben"-eq 7] && Sed-nr-i.bak ' s/(. *linux= ". *)"/\1 xxxxxxxx "/P '/etc/default/grub | | Exit 20
The additional section can also be used in this way: Sed-r ' s/quiet/& xxxx/'/etc/default/grub (the & symbol in the sentence represents all the preceding characters)
4. Use SED to remove the base name and directory name from the/etc/sysconfig/network-scripts/
Solution: echo/etc/sysconfig/network-scripts/| Sed-nr ' s#.*/(. +)/?#\1#p ' Take the base name
echo/etc/sysconfig/network-scripts/| Sed-nr ' s# (. *) (. +)/?#\1#p ' Fetch folder name
echo/etc/sysconfig/network-scripts/| Sed-nr ' s# (. *) (. +)/?#\2#p ' Take the base name
5, using SED will/etc/httpd/conf/httpd.conf #namevirtualhost *:80 Remove the # number, while the last 7 lines of # are removed
Solution: Sed-e ' s/#Name/name/'-e '/#<virtualhost/,/#<\/virtual/s/#//'/etc/httpd/conf/httpd.conf
Linux Text processing tools sed exercises