Grep special characters

Source: Internet
Author: User
Special character of grep-General Linux technology-Linux technology and application information. The following is a detailed description. First, check ^ $:
$ Grep-n' \ ^ 'grep.txt
$ Grep-n' ^ 'grep.txt
$ Grep-n "^" grep.txt
$ Grep-n "\ ^" grep.txt
Both the first and last lines match the row containing ^ characters, while the two lines in the middle both output all rows, as shown in the same way as $.

Let's look at "* [] () | \ +?
$ Grep-N'. 'grep.txt
$ Grep-n' \. 'grep.txt
$ Grep-n "." grep.txt
$ Grep-n "\." grep.txt
The first and third outputs all rows, and the other two outputs contain rows.

The above four forms of command output can contain * +? .

For the above four forms of commands, if the command line does not contain \, you can output the line containing |, and add \ to output all lines.

$ Grep-n' \ 'grep.txt
Grep: Trailing backslash
$ Grep-n' \ 'grep.txt
31 :\
$ Grep-n "\" grep.txt
>-Bash: unexpected EOF while looking for matching '"'
-Bash: syntax error: unexpected end of file
$ Grep-n "\" grep.txt
Grep: Trailing backslash

$ Grep-n' ['grep.txt
Grep: invalid regular expression
$ Grep-n' \ ['grep.txt
27 :[
$ Grep-n "\ [" grep.txt
27 :[
$ Grep-n "[" grep.txt
Grep: invalid regular expression

$ Grep-n "(" grep.txt
35 :(
$ Grep-n "\ (" grep.txt
Grep: Unmatched (or \(
$ Grep-n' \ ('grep.txt
Grep: Unmatched (or \(
$ Grep-n' ('grep.txt
35 :(

For ", except $ grep-n" grep.txt is not allowed.

', Except $ grep-n "'" grep.txt.


Why is there such an odd rule? Hope you can give me some advice! Thank you!

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.