Shell Programming Four Musketeers practice--grep

Source: Internet
Author: User
Tags egrep

grep (Global search Regular expression (RE) and print out of the line, fully search regular expressions and print out the lines)
grep is a powerful text search tool that uses regular expressions to search for text and prints matching lines without modifying the original file contents.

The grep family of Unix includes grep, Egrep, and Fgrep. Egrep and Fgrep commands are only a small difference from grep. Egrep is the extension of grep, which supports more re metacharacters, and fgrep is fixed grep or fast grep, which regards all the letters as words, that is, the metacharacters in the regular expression represents the literal meaning back to itself, no longer special.

Linux uses the GNU version of grep. It is more powerful and can use the Egrep and FGREP functions with the-G,-e,-f command line Options


1. Remove the etc/passwd, with the root row, and display the line numbers of the rows in the/etc/passwd

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7A/38/wKioL1alxBSCrtStAAAxWLER6_o827.png "title=" Grep.png "alt=" Wkiol1alxbscrtstaaaxwler6_o827.png "/>

Use-N to display line numbers

grep can use--color=auto to display the keyword portion using color.


2. Reverse the selection of/etc/passwd in the root

650) this.width=650; "style=" width:650px;height:293px; "src=" http://s2.51cto.com/wyfs02/M01/7A/39/ Wkiom1alxvxht5joaabbcbnnoco338.png "title=" 22.png "alt=" wkiom1alxvxht5joaabbcbnnoco338.png "border=" 0 "height=" 293 "hspace=" 0 "vspace=" 0 "width=" 650 "/>


3. Display two rows above and below the specified line

650) this.width=650; "style=" width:650px;height:95px; "src=" http://s4.51cto.com/wyfs02/M02/7A/39/ Wkiol1alx7frkwzgaaajalyw5vu240.png "title=" Auto.png "alt=" wkiol1alx7frkwzgaaajalyw5vu240.png "border=" 0 "height=" "hspace=" 0 "vspace=" 0 "width=" 650 "/>


4. Display version Information-V

650) this.width=650; "style=" width:650px;height:123px; "src=" http://s1.51cto.com/wyfs02/M00/7A/39/wKioL1alyInxBB_ Gaaarzeezp7u197.png "title=" V.png "alt=" wkiol1alyinxbb_gaaarzeezp7u197.png "border=" 0 "height=" 123 "hspace=" 0 " Vspace= "0" width= "650"/>


5. if referenced by \< and \>, use the expression as a single word search-W

650) this.width=650; "style=" width:650px;height:110px; "src=" http://s3.51cto.com/wyfs02/M01/7A/3A/ Wkiol1alyrrbcl83aabaro9ylrg272.png "title=" Sin.png "alt=" wkiol1alyrrbcl83aabaro9ylrg272.png "border=" 0 "height=" "hspace=" 0 "vspace=" 0 "width=" 650 "/>


6. Search for "I" in a case-sensitive manner

650) this.width=650; "style=" width:660px;height:300px; "src=" Http://s3.51cto.com/wyfs02/M00/7A/3A/wKiom1alyafg_ 8svaage3jlpejg206.png "title=" Color.png "alt=" wkiom1alyafg_8svaage3jlpejg206.png "border=" 0 "height=" hspace= "0 "vspace=" 0 "width=" 660 "/>


7. Display the line "^" Starting with a character

650) this.width=650; "style=" width:600px;height:263px; "src=" http://s2.51cto.com/wyfs02/M00/7A/3A/ Wkiol1alyviiiscyaaacb5qxpdw661.png "title=" start. png "alt=" wkiol1alyviiiscyaaacb5qxpdw661.png "border=" 0 "height=" 263 "hspace=" 0 "vspace=" 0 "width=" "/>


8. Displays the line "$" ending with a character

650) this.width=650; "style=" width:600px;height:238px; "src=" http://s5.51cto.com/wyfs02/M01/7A/3A/ Wkiol1aly0ltlboxaaafhdszlau914.png "title=" end. png "alt=" wkiol1aly0ltlboxaaafhdszlau914.png "border=" 0 "height=" 238 "hspace=" 0 "vspace=" 0 "width=" "/>


9. Egrep

650) this.width=650; "style=" width:600px;height:311px; "src=" http://s5.51cto.com/wyfs02/M01/7A/3B/ Wkiom1alzv3dxflkaaakuzut3-k739.png "title=" egre.png "border=" 0 "height=" 311 "hspace=" 0 "vspace=" 0 "width=" alt= " Wkiom1alzv3dxflkaaakuzut3-k739.png "/>


650) this.width=650; "style=" width:600px;height:121px; "src=" http://s5.51cto.com/wyfs02/M00/7A/3B/ Wkiom1alzabglkplaaapwvt7yh4258.png "title=" fd.png "border=" 0 "height=" 121 "hspace=" 0 "vspace=" 0 "width=" alt= " Wkiom1alzabglkplaaapwvt7yh4258.png "/>

This article is from the "Records" blog, so be sure to keep this source http://lwj421.blog.51cto.com/7119945/1738275

Shell Programming Four Musketeers practice--grep

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.