Get the App
SLTechnology News&Howtos  ›  Servers  › 

Regular expression (gerp)

Shulou Source: shulou.com Published: 2022-06-03 04:24:41 09月11日 Update

1. Grep

Command format: grep [- cinvABC] 'word' filename

-c indicates the number of lines printed that meet the requirements

-I means ignore case

-n indicates the number of lines that output meets the requirements and their line numbers

-v means to print all numbers that do not meet the requirements

-r traverse all subdirectories

-An is followed by a number, such as-A2 to print the lines that meet the requirements and the two lines below

-B is followed by a number, and a column such as-B2 indicates printing the lines that meet the requirements and the two lines above

-C is followed by a number, such as-C2 to print the lines that meet the requirements and two lines up and down

Create a grep directory and copy a file / etc/passwd

Filter files that contain nologin in passwd

Here, the red color is marked after filtering, because there is a-color=auto in the grep, which adds a color display.

Grep to view the number of rows that meet the requirements-c

Grep-n shows the number of lines that contain nologin in this file

Grep-I is case-insensitive

Grep-v is reversed, except for nologin.

Traverse all subdirectories-r

-A2 prints out the line containing root and the two lines below this line

-B2 prints out the line containing root and the two lines above this line

-C2 prints out the line containing root, as well as both the top and bottom lines of this line

Look at all the numbers from 0 to 9 in a file. [] parentheses indicate any character in it.

Reverse-r to bring out the ranks that do not contain numbers

Filter all lines that begin with #

Filter all lines that do not begin with the # sign

Lines that filter numbers that do not start with 0-9 are displayed

What does it begin with outside the square brackets? inside the square brackets, it means to take the wrong and take the opposite.

Filter any character

Specifies the number of occurrences of characters to be filtered out, and must use egrep if you do not want to use topological symbols

Specifies that one or more specified characters are to be filtered

Filter out 0 or 1 specified character

Filter out string 1 or 2, which means "or".

. Represents any character

There are zero or more characters before the sign.

{} indicates a range

+ means to match one or more characters preceding +.

? Mean? There are zero or 1 characters before it.

| indicates or

Tags: Character number beginning file face multiple up and down size subdirectory string meaning square brackets commands parentheses copy format number directory symbol Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei Redmi Linux Shulou Tech Info