Linux shell BASICS (8) and Linux shell Basics

Source: Internet
Author: User

Linux shell BASICS (8) and Linux shell Basics
8. Use the stream Editor of shell script sed & awk01.sed-Steam Editor # ed/etc/passwd1, 10 p ...... 1 s/root/byf/p (replace root with byf) # sed-e's/root/byf/G'/etc/passwd (same as above) only the displayed content changes # sed-e's/root/byf/G'/etc/passwd>/tmp/a # cp/tmp/a/etc/passwd # sed -n-e '/\ <byf \>/p (print rows containing byf words) '/etc/passwd # sed-n-E'/\ <byf \>/d (delete rows containing byf words) '/etc/passwd # sed-E'/\ <byf \>/s/bash/nologin/G'/etc/passwd>/tmp/a # cp/tmp/ /etc/passwd (file replacement, is equivalent to modifying the passwd file) # vi/etc/squid. f # sed-e '/^ #/d'-e'/^ $/D'/etc/squid. Conf | wc-l (delete # comment rows, and rows starting with spaces to quickly display useful rows) # sed-e '/bash/s/byf/root/G'/etc/passwd (modify the root containing bash rows to byf) multiple replications # sed-e ''-e'' # sed-e': :( colon separation command) '# sed-e' 1 ~ 2' (execute 1, 3, 5 ,......) Step 2 # sed-e's/root/byf/'-e's/bash/nologin'/etc/passwd # vi ssss/root/byfs/bash/nologin # sed-f sss/etc/passwd (the result is the same as-e ''-e '') # vi sss #! /Bin/sed-fs/root/byfs/bash/nologin # chmod a + x sss #. /sss/etc/passwd02.awk # man sed # info sed (view sed information function) (you can view examples of sed, * click enter to jump to the specified sed instance) sed can process row content awk can process column content # chkconfig -- list | awk '{print $5}' 3: off3: off3: on ...... # Chkconfig -- list | awk '$1 = "httpd" {print $5}' 3: on # if [chkconfig -- list | awk '$1 = "httpd" {print $5}' = "3: on"]; then echo OK; fiok # chkconfig -- list | awk '{print $1 "on level" $5}' | 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 (what is the separator, Here ':'): '{print $1 "UID is" $3}'/etc/passwd write script # vi aaaBEGIN {iii = 0} {if ($5 = "3: on ") iii = iii + 1} END {print iii}: wq # chkconfig -- list | awk-f may be used for log analysis

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.