Eight, shell script sed&awk01.sed using the Flow editor-steam editor#ed/etc/passwd1,10p ... 1s/root/byf/p (replace root for BYF) #sed-E ' s/root/byf/g '/etc/passwd (function as above) just show the content change #sed-e ' s/root/byf/g '/etc/passwd >/ tmp/a#cp/tmp/a/etc/passwd#sed-n-E '/\<byf\>/p (print lines containing byf words) '/etc/passwd#sed-n-e '/\<byf\>/ D (delete lines containing byf words) '/etc/passwd#sed-e '/\<byf\>/s/bash/nologin/g '/etc/passwd >/tmp/a#cp/tmp/a/etc/ passwd (file replacement, equivalent to modify passwd file) #vi/etc/squid/squid.f#sed-e '/^#/d '-e '/^$/d '/etc/squid/squid.conf |wc-l (Delete # comment lines, and a line starting with a space, a quick display of useful lines) #sed-e '/bash/s/byf/root/g '/etc/passwd (Modify the root containing bash lines to BYF) multiple times replace #sed-e '-e ' #sed-e '::(colon-separated command) ' #sed-E '-1,3,5 ' (for the implementation of section,......) Step length is 2#sed-e ' s/root/byf/'-e ' s/bash/nologin '/etc/passwd#vi ssss/root/byfs/bash/nologin#sed-f sss/etc/passwd (Result ditto-e ') '-e ') #vi sss#!/bin/sed-fs/root/byfs/bash/nologin#chmod a+x Sss#./sss/etc/passwd02.awk use #man sed#info SED (see the information function of SED) (see Examples of sed, * Click Enter to jump to the specified sed instance) SED can process the contents of the row awk can handle the contents of the column #chkconfig--list |awk ' {print $} ' 3:OFF3 : OfF3:on. #chkconfig--list | awk ' $1== ' httpd ' {print $ ' 3:on#if [chkconfig--list | awk ' $1= ' httpd ' {print $ ' = ' 3:on ']; then echo OK; Fiok#chkconfig--list |awk ' {print $ ' on ' $ $ ' | Head#chkconfig--list | awk ' begin {iii=0}{if ($5== "3:on") Iii=iii+1}end{[print III} ' #awk ' begin {iii=0}{if ($7== "/bin/bash") iii=iii+1}end { Print III} ' </etc/passwd#awk-f (as a delimiter, here is ': '): ' {print $ ' UID is ' $ $} '/etc/passwd write script #vi aaabegin{iii=0}{if ($5== "3:on") Iii=iii+1}end{print iii}:wq#chkconfig--list | Awk may be used when awk-f AAA log analysis
Linux Shell Entry Basics (eight)