Linux Normal table-positional meta-characters

Source: Internet
Author: User

There are two metacharacters used to specify that the string is at the beginning or end of the line. The caret (^) is a form that indicates the beginning of the word regular. The dollar sign ($) is the normal form of a single character that indicates the end of a line. These are often referred to as "locators," because they limit the match to a specific location. For example, you can use the following expression to print a line beginning with first:
^first
There is no ^ meta-character. This expression will print a random line that includes first.

Usually. Use VI to enter the text to be processed by troff, and do not want the space to be the end of today's line. Assuming that you want to find (and delete) them, the following normal expressions can match the line with one or more spaces at the end:
--*$

Troff requests and macros must be entered at the beginning of the row. They are a two-character string. preceded by a period.

Suppose a request or a macro has a number of parameters. Then it usually has a space behind it. The regular expressions used to search for such requests are:
^\... -

This expression matches the line with a period at the beginning of the row, followed by a two-character string, and then a space.
The ability to match a blank line using two contiguous positional metacharacters, namely: ^$

The ability to use this pattern to calculate the number of empty lines in a file, using the Count option-C in grep:

$ grep-C' ^$ 'Ch04
5

Suppose you want to use SED to delete empty rows. So this is a very practical form of expression.

The following regular expressions can be used to match blank lines, even if they include spaces:
^-*$

Same. The ability to match an entire row with the following expression: ^.*$

In sed (and grep), it is only special when "^" and "$" are present at the beginning or end of the current form.

So "^abc" means "match only the letters A, B, and C at the beginning of the line, and" ab^c "means" match A, B, character ^, and then C "at any position in the line.

This is used for the same "$".

It is different in awk. "^" and "$" are always special. Even if they may make the written regex match whatever it is.

To be able to say, in awk, when you want to match the character "^" or "$", no matter where it is in the normal form, it should be escaped with a backslash.

References: http://www.linuxawk.com/communication/441.html

Linux Normal table-positional meta-characters

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.