Regular expressions in the shell

Source: Internet
Author: User
1. Regular and wildcard characters

The wildcard characters in Linux are used to match the file names, and their matches are exact matches. Only wildcard characters are supported, command has LS find CP and other commands

The regular is used to match the string, and is to contain the match. As long as the search is in a string, the string is considered eligible, and the supported commands are grep awk sed.

2. Rules

Blank line matching, let's first look at the text file with blank lines what is it like?

As you can see, when we finish writing a line that belongs to carriage return, we are actually using $ as the end sign. So the end of a match in a regular expression with a line ending in xx (eg:. html$) is the result. The third line in the figure is made up of multiple spaces. So how do we get rid of the blank lines in the text?

Note that the ^ here has two meanings: the beginning, and also the non.

You can see that when you match "^$", only the second line is displayed, which represents the line beginning with $. When "[^$]" is matched, only the second line is not displayed. If the ^ is simply understood to be non-time, then the match does not have a $ row, the result should not be displayed. Therefore the ^ here should have also with $ for the beginning meaning.

Regular expressions in the shell

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.