Shell Learning--Regular expression

Source: Internet
Author: User

1. Explanation: A single string that describes or matches a series of strings that conform to a certain syntactic rule.

Action object: String

Many are used in document editors or other tools to retrieve and replace text content that conforms to patterns.

Common Grep,sed,awk

2.grep filtering, printing;-incvabc

-I ignores case,-n displays line numbers, and-c counts the number of rows that meet the requirements;-V prints rows that do not conform to the requirements,-an prints rows that match and the next n rows,-bn on n rows,-cn up and down n rows.

grep ' halt '-n-a2/home/jason/passwd prints the line that meets the requirements and the following two lines, plus the line number display

grep ' bash '-c passwd prints rows that meet the required line number

Grep-nv ' nologin ' passwd prints lines without nologin and displays line numbers

grep ' [0-9] ' passwd prints all rows that contain numbers

Grep-v ' ^# ' inittab print all lines that do not start with #

Grep-v ' ^# '/home/jason/inittab |grep-v ' ^$ ' prints all lines that do not start with # and are not empty

Vim Greptest2.txt

123

Abc

55W


abc2345

#ljadj

grep ' ^[^a-za-z] ' greptest2.txt prints lines that do not start with a letter, [^] table negation, except for characters inside []

grep ' [^a-za-z] ' greptest2.txt contains characters other than letters

Shell Learning--Regular expression

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.