Shell programming in linux-Regular Expressions

Source: Internet
Author: User
Tags egrep


Shell programming regular expression:

1: metacharacters []. *? + () | {}^ $

2: [a-z0-9] indicates one that matches any number and letter

3: [^ a-z] matches any letter

4: AB + c + indicates matching the characters before one or more plus signs.

5: AB * c * indicates that no or more characters before * are matched.

6: AB? C? Indicates matching? Character before

7: (AB) {2} c Represents a string that matches two AB characters.

8: (AB) * c (AB) + c (AB )? C has the same rules as 4, 5, and 6, but matches all characters in brackets.

9: ^ AB indicates matching the characters starting with AB, while [^ AB] indicates matching

10: \ <title \> only matches the word title, with spaces or line breaks as the Separator



In linux, The fgrep grep egrep command grep (global research regular expression and printing)

The fgrep command does not use regular expressions and matches all characters as common characters during search.

The grep command only supports regular expressions and does not support extended regular expressions.

The egrep command supports all extended regular expressions.




Common grep usage:

1: grep-v match the character grep-v '^ AB'/etc/passwd that is not included in the regular expression and does not start with AB

2: grep -- color: Mark matched characters in color.

3: grep-o only displays matched characters after filtering.

4: grep-A2 'abc'/etc/passwd: displays the matching characters and the above two lines matching the Character Line

5: grep-B2 'abc'/etc/passwd: displays the matching characters and the following two lines matching the character lines

6: grep-C3 'abc'/etc/passwd: displays the matching characters and the following and above two lines of the matching Character Line

7: grep-f/etc/shadow/etc/passwd indicates that the/etc/passwd file contains

Characters in/etc/shadow

8: grep-E indicates that extended regular expressions are supported, which is equivalent to egrep.

9:











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.