Chapter 3 Regular Expressions for Shell Learning

Source: Internet
Author: User

Regular Expression

\ <The \>: exact match of the, excluding words containing

[^ B-d]: does not contain B ~ D

A \ {2 \}: A appears twice

A \ {2, 3 \}: A appears 2 ~ 3 times

A \ {2 ,\}: A appears at least twice

[: Upper:]: uppercase letters (when used, add a layer of [] to indicate matching Character Set combination)

[: Lower:]: lowercase letter

[: Digit:]: Number

[: Alnum:]: uppercase/lowercase letters and numbers

[: Space:]: space or tab key

[: Alpha:]: uppercase/lowercase letters

Wildcard

Note that the wildcard is different from the regular expression, although there are common symbols

Ls-L *. Sh

Matches the file ending with. Sh, and * Indicates 0 or multiple prefix characters in the regular expression.

Ls-l 0 ?. Sh

Match the file that starts with 0 and ends with a character, ending with. Sh, and? Represents 0 or 1 character in an extended regular expression.

[] And [^] are used in the same way as regular expressions.

Grep

Text Search Tools

Grep [Option] [mode] [file]

-C only outputs the number of matched Korean

-I case-insensitive

-L only list matching file names, not specific Matching lines

-N: Lists All matched rows and displays row numbers.

-S does not display error messages that do not exist or do not match the text

-R recursive search not only searches for the current working directory, but also subdirectories

-Q: no result is output. Exit indicates whether the search is successful.

-E supports extended regular expressions.

-F does not support regular expressions and matches strings according to their literal meanings.

-H: When querying multiple files, the file name is not displayed.

-B prints the offset of the matched line spacing header, in bytes. If combined with-o, it is the offset of the matching word from the header.

-W matches the entire word, that is, the metacharacters of the regular expression in the pattern are not interpreted as special meanings. For example, CER * Is CER *

-X matches the entire line, that is, if word * is matched, the line of words can be word *.

Note: If the mode has spaces, use quotation marks. The file name can use wildcards (note that it is not a regular expression).-At the beginning must also be added to \ for transfer (think-option)


This article is from the "flyclc" blog, please be sure to keep this source http://flyclc.blog.51cto.com/1385758/1540161

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.