Linux Command--grep command usage Daquan

Source: Internet
Author: User

1. Parameters:
-I: Ignore case
-C: Print the number of matching rows
-L: find included matches from multiple files
-V: Find rows that do not contain matches
-N: Print row and row labels that contain matches


2, RE (regular expression)
\ ignore the original meaning of special characters in regular expressions
^ matches the start line of the regular expression
$ matches the end line of a regular expression
\< starting from the line that matches the regular expression
\> to the end of the line that matches the regular expression
[] A single character, such as [a] that a meets the requirements
[-] range, such as [A-z], i.e. a,b,c to Z all meet the requirements
. All the individual characters
* All characters, length can be 0

3. Example
# Ps-ef | grep in.telnetd
Root 19955 181 0 13:43:53? 0:00 in.telnetd

# more Size.txt The contents of the size file
b124230
b034325

# More Size.txt | grep ' [A-b] ' range, such as [A-z], i.e. a,b,c to Z all meet the requirements
b124230
b044525


# More Size.txt | grep ' [A-b] ' *
b124230
b034325

# More Size.txt | grep 'B ' single character, if [a] is a compliance requirement
b124230
b034325

# More Size.txt | grep ' [BB] '
b124230
b034325
b103303


# grep ' Root '/etc/group
Root::0:root
Bin::2:root,bin,daemon
Sys::3:root,bin,sys,adm
Adm::4:root,adm,daemon
Uucp::5:root,uucp
Mail::6:root
Tty::7:root,tty,adm
Lp::8:root,lp,adm
Nuucp::9:root,nuucp
Daemon::12:root,daemon


# grep ' ^root '/etc/group matches the start line of the regular expression
Root::0:root

# grep ' UUCP '/etc/group
Uucp::5:root,uucp
Nuucp::9:root,nuucp

# grep ' \&LT;UUCP '/etc/group
Uucp::5:root,uucp

# grep ' root$ '/etc/group matches the end line of the regular expression
Root::0:root
Mail::6:root

# More Size.txt | Grep-i ' B1. '-I: Ignore case
b124230
b103303
B103303

# More Size.txt | Grep-iv ' B1. '-V: Find rows that do not contain matches

b034325
a081016

# More Size.txt | Grep-in ' B1. "
1:b124230

# grep ' $ '/etc/init.d/nfs.server | Wc-l
128
# grep ' \$ '/etc/init.d/nfs.server | Wc–l ignores the original meaning of special characters in regular expressions

15
# grep ' \$ '/etc/init.d/nfs.server
Case "$" in
>/tmp/sharetab.$$
["x$fstype"! = Xnfs] &&

# more Size.txt

The test file
Their is files
The end

# grep ' the ' size.txt
The test file
Their is files

# grep ' \<the ' size.txt
The test file
Their is files

# grep ' the\> ' size.txt
The test file

# grep ' \<the\> ' size.txt
The test file

# grep ' \<[tt]he\> ' size.txt
The test file

Linux Command--grep command usage Daquan

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.