Python Full Stack road Day8

Source: Internet
Author: User
Tags egrep

first edited September 24, 2017 16:25:02

Summary
I. Cure command
Two. grep and regular expressions
Three. Sed and regular expressions
Four. Awk and regular expressions
Five. Other commands
Homework
Summary today

Summary

Citation: Mr. Haifeng

    1. How to cure commands
    2. Regular expressions under grep and SED
I. Cure command
    1. Shell Login
      • /etc/profile
      • /etc/bashrc
      • /root/.bashrc
      • /root/.bash_profile
      • /etc/profile.d/a.sh
    2. Non-Shell landing
      • /root/.bashrc
      • /etc/bashrc
      • /etc/profile.d/a.sh
Two. grep and regular expressions
  1. Grep
    • -N: Show line numbers
    • -O: Show only matching content
    • -Q: Silent mode, no output, you have to use $? To determine the success of the execution, that is, there is no filtering to the desired content
    • -L: If the match succeeds, only the file name is printed, the failure is not printed, usually-rl together, grep-rl ' root '/etc
    • -A: If the match is successful, the matching row and the subsequent n rows are printed together
    • -B: If the match succeeds, the matching row and its first n rows are printed together
    • -C: If the match succeeds, the matching row and its n rows are printed together
    • -C: If the match succeeds, the number of rows to match is printed
    • -e: Equals Egrep, extended
    • -I: Ignore case
    • -V: Inverse, mismatch
    • -W: Match word
  2. The regular introduction
    • ^: Beginning of the line
    • $: End of line
    • . : Any single character other than line break
    • . *: All characters
    • *: 0 or more leading characters
    • +: One or more leading characters
    • ? : A leading character 0 or one
    • X{M}: X appears m times
    • X{m,}: X appears m times to multiple times (at least m times)
    • X{m,n}: Appears m to n times
    • []: Any character within a group of characters
    • [^]: reverse each character within a character group (does not match each character in a group of characters)
    • ^[^]: A line that begins with a character in a non-character group
    • \-: Can only be placed at the end
    • [A-z]: lowercase letters
    • [A-z]: uppercase
    • [A-Z]: lowercase and uppercase letters
  3. Regular expressions and wildcard characters
    • Wildcard: Use with commands
    • Regular expressions: Generally used for text processing
Three. Sed and regular expressions
    1. SED syntax
      • sed [options] ' command ' in_file[s]
        • Options section
          • Sed-n ' action ': Silent
          • Sed-e ' actions ': multiple rules
          • Sed-i ' action ': directly modify read content and write
          • Sed-f ' action ': write the action in a file;
        • Command section
          • ' [Address 1, Address 2] [function] [parameter (tag)] '
          • method of addressing 1. Number 2. Regular
          • Function
            • Delete and change
            • A rear plug
            • C Replace
            • I front insert
            • D Delete
            • Input/Output
            • P Print matching line general and-n parameter to mask default output
            • R read in from file
            • W Write to File
            • s string Substitution s/old/new/[g] (g means all modifications in one line)
            • (): Save matched characters for reverse reference \ n use up to 9 label label order from left to right
Four. Awk and regular expressions
  1. awk syntax: awk [options] ' commands ' files
    • -F defines the field delimiter, the default delimiter is a contiguous space or tab, and defines the interval symbol with the-f parameter in option
    • Use The order of 2,$3 to represent the different fields of each row in files separated by the interval symbol
    • NF variable indicates the number of fields in the current record
    • NR indicates the number of rows that awk reads in
    • Row handling: Addressing commands
      • Addressing methods: Regular, variable, comparison, and relational operations
      • ~!~: Match regular or mismatched, regular need/regular/Surround
    • -V Define variables and assign values can also be borrowed from the shell variable to introduce
      • Username=root
      • Awk-v var=$username-f: '$1 = = Var{print $1,nr,nf} '/etc/passwd
Five. Other commands
    1. Cat File | Sort | Uniq: File sort to go heavy
    2. cut-d delimiter-fm,n: Processing file with delimiter cut to take section M n part
    3. Du-sh: Statistics File size
    4. Find path-type f: Finding ordinary files by type
    5. Find path-name file name: Finding files by name
    6. Find path-size +30m: Finding files larger than 30M
    7. Find path-size +10m-size-30m: Find files larger than 10M less than 30M
    8. Find/-size +2m-type f-name *.txt
Homework
    1. Regular expressions and character processing
      Target file/etc/passwd, using the grep command or Egrep
      1. All rows containing root are displayed:
      2. Output any rows that contain bash, and also output the contents of the next two lines, followed by the row:
      3. Shows how many lines contain nologin.
      4. Shows that the rows contain root and the line number is output.
      5. Displays the file in the
      6. New user
        Abominable
        Abominate
        Anomie
        Atomize
        Write regular expressions and match them up
        Egrep ' A.omi (nabl|nat|z|) E '/etc/passwd
      7. Built four users
        Alex213sb
        wpq2222b
        Yh438pig
        egon666
        Egon
        Filter out the user name consists of a letter + number + letter Line
        [Email protected] ~]# egrep ' ^[a-z]+[0-9]+[a-z]+ '/etc/passwd
      8. Displays all filenames containing root in/etc directory
      9. Filter out all comments and all blank lines in/etc/ssh/sshd_config
        Grep-v ' ^# '/etc/ssh/sshd_config |grep-v ' ^ *$ '
Summary today

Python Full Stack road Day8

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.