15-grep Concise Pen

Source: Internet
Author: User

Searching for patterns in files

grep [options] pattern [file-list]


pattern is a regular expression,file-list is the list of path names for grep to search for plain text files


-C displays only the number of rows in each file that contain a matching pattern

-V displays rows that do not contain a matching pattern

-I ignores case

-A in a binary file, search for data as a text file

-O shows only the content that matches RegExp (the number of times that the user statistics appear in the file)

-N matches the line number displayed at the beginning of the

-E extended grep, i.e. Egrep

-color=auto highlighting match keywords in a specific color

-A after means displaying data that matches a string and its following n rows

-B before, displaying data that matches a string and its first n rows

-C context displays the matching string and its front and back num rows

-W word search, equivalent to \b.


Original file

1$CatTesta2 Aaabb3 BBBCC4ff-FF5 CCCDD6 Dddaa7$CatTestb8 AAAAA9 bbbbbTen CCCCC One ddddd A$CatTESTC - AAAAA - bbbbb theCcccc

1 grep BB Testa 2 Aaabb 3 BBBCC

Searching for lines in Testa that contain the string bb

1 grep -v BB testa2 ff-ff3CCCDD4 Dddaa

Searching for rows in Testa that do not contain matching strings

1 grep -n bb testa21: Aaabb32: BBBCC

Displays the line number of the matching row

grep *
1 grep BB *2testa:aaabb3testa:bbbcc4 testb:bbbbb

Search for matches in multiple files

1 grep -I BB * 2testa:aaabb  3testa:bbbcc  4testb:bbbbb 5 testc:bbbbb 6 grep -I BB * 7testa:aaabb  8testa:bbbcc  9Testb : bbbbb testc:bbbbb

Case-insensitive matching

1 grep -C BB* 2 Testa:23 testb:14 TESTC:0

Show only the number of rows matched in each file

15-grep Concise Pen

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.