Linux Shell Basics (eight)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.