Grep basic operations

Source: Internet
Author: User

Grep usage
1. Basic usage
Syntax: grep [Options] RegEx File
Here, RegEx is the regular expression file, which is the name of the text file to be matched. You can specify multiple
Eg:
$: Ls/usr/bin> dirlist-usr-bin.txt
$: Ls/sbin> dirlist-sbin.txt
$: Ls/usr/sbin> dirlist-usr-sbin.txt
$: Grep tou dirlist-bin.txt
Touch
Tou is a regular expression that matches rows containing the TOU string, because execution in shell command lines should avoid expansion before execution, and the standard writing should be
Grep 'tou' dirlist-bin.txt to avoid unnecessary errors.

2 options
-I case-insensitive

-V reverse matching

-L output the file name containing the matching string

-L output file names that do not contain matching strings
$ Grep-l 'tou '*
Dirlist-sbin.txt
Dirlist-usr-sbin.txt

-H: Only output matching file names

-N: Output matched rows
$ :~ /Jiangjian/NOTE/TEMP $ grep-N 'tou' dirlist-bin.txt
Dirlist-bin.txt: 141: Touch


3. [] usage
If you want to avoid shell extension, you can write regular expressions in "'" and "'". Here, you can use "[" and "]" to match certain character sets, if the match is successful, except for the two metacharacters "^" and "-", other metacharacters are not escaped, matches with ordinary characters,
$: Grep '[BG] Zip 'dirlist-*. txt
Dirlist-bin.txt: Bzip2.
Dirlist-bin.txt: bzip2recover.
Dirlist-bin.txt: Gzip
Note that dirlist-*. txt in the command line has been extended before execution.




Grep basic operations

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.