Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Regular expression (gerp)

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report