Regular Expressions-2015.8.27 jobs

Source: Internet
Author: User
Tags expression engine egrep

1.grep command

1.1 grep [OPTIONS] PATTERN [FILE ...] :

Parameters:

--color=auto: highlighting the matching characters;

-V: The display mode does not match the row;

-I: ignore character case;

-O: Displays only strings that can be matched to the pattern;

-Q: Silent mode;

-E: Using extended regular expressions;

1.2 Rules

1) Number of times matching: Used to specify the number of times the character behind;

    • *: any time;

    • \?:0 or 1 times;

    • \+:1 or multiple times;

    • \{m\}: Precisely limited to M times;

    • \{m,n\}: At least m times, up to n times, [M,n]

    • \{0,n\}: Up to n times;

    • \{m,\}: at least m times;

    • . *: Matches any character of any length;

2) Position anchoring:

    • ^: Anchor at the beginning of the line, for the leftmost mode;

    • $: End of line anchoring; for the rightmost side of the pattern;

    • \< \b: The first anchor of the word; the left side of the pattern used to denote the word;

    • \> \b: the ending anchor; the right side of the pattern used to represent the word;

    • ^$: blank line;

3) Group: \ (\)

The contents of the pattern in the grouped parentheses are recorded by the regular expression engine during execution, and the built-in variables are saved: The variables are \1, \2, ...

\1: From the left, the first opening parenthesis, and the matching right parenthesis in the middle of the pattern match to the content;


4) Back reference: Use the variable to refer to the character that matches the pattern in the preceding grouping brackets;

1.3 Extending regular expressions

1) The grep family has three commands:

    • grep: basic Regular expression

      • -e: extending regular expressions

      • -F: Regular expressions are not supported

    • Egrep: Extending Regular expressions

    • Fgrep: Regular expressions are not supported

2) Character matching:

    • .: Any single character

    • []:

    • [^]:

3) Number of matches:

    • *: Any length

    • ?: 0 or 1 times;

    • +: more than 1 times;

    • {m}: exact match m times;

    • {M,n}: At least m times, up to n times;

4) Anchoring:

Same as the basic

5) Group: ()

Back reference: \1, \2, ...

6) OR:

A|b

C|cat: does not represent cat or cat, but is C or cat;

To be written (C|c) at

1.4 Configuring Permanent Alias

Because it is often necessary to highlight the matching characters, and use alias to configure aliases, only valid for this process, it is necessary to configure the permanent effect, the steps are as follows:

1) Just use the current user:

Vim ~/.BASHRC

2) Used by all users:

Vim/etc/bashrc

3) Add Content:

Alias grep= ' grep color=auto '

4) The following code is required to take effect when the modification is complete:

SOURCE ~/.BASHRC

Or:

Source/etc/bashrc


2. Display the lines in the/etc/passwd file that end with bash

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B9/wKioL1XsGyLTQX5yAACaR84cs2c450.jpg "/>


3. Display the two-digit or three-digit number in the/etc/passwd file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/BC/wKiom1XsGPqTkg_6AACYMYUpWrw617.jpg "/>


4. display lines with ' LISTEN ' followed by 0, one or more whitespace characters in the ' netstat-tan ' command result

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/B9/wKioL1XsGyKgiiTyAAFriyrZ9fQ278.jpg "/>


5. Add user Bash,testbash, basher and Nologin user (Nologin user shell is/sbin/nologin) and then find out/etc/ The line of the user name in the passwd file with the shell name;

Add Users:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/BC/wKiom1XsGPqgvor9AAC6hWhd67I338.jpg "/>

Grep:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/B9/wKioL1XsGyKjC6JlAAFIqTDgink623.jpg "/>


6. Displays the default shell and UID for root, CentOS, or User1 users on the current system

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/BC/wKiom1XsGPrzgWePAAC3um86ot8286.jpg "/>


7. Find a word in the/etc/rc.d/init.d/functions file (the middle of the word can be underlined) followed by a set of parentheses on the line

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/B9/wKioL1XsGyKDOrUMAAF1MwTw2zs884.jpg "/>


8. use echo to output a path, and then egrep to find its path base name; further: Use Egrep to remove its directory name;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/BC/wKiom1XsGPugRZWPAACLw9Y6Lns777.jpg "/>


9. Find the number between 1-255 in the result of ifconfig command execution

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/BC/wKiom1XsGVrAfcjkAAMnCUYIOWg038.jpg "title=" Qq20150906184352.jpg "alt=" Wkiom1xsgvrafcjkaamncuyiowg038.jpg "/>




Regular Expressions-2015.8.27 jobs

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.