Shell–grep Common usage

Source: Internet
Author: User
Tags egrep

is a powerful text search tool that can use regular expressions to search for text and print matching lines.
I often use it to find strings such as:

    grep -rn "字符串" .

Recursively finds the "string" in all files in the current directory and the line in which it is marked.

Here's a look at the specific parameters:

    grep [-acinv] [--color=auto] ‘搜寻字符串‘ filename 选项参数:    -a :将 binary 档案以 text 档案方式搜寻数据    -c :计算找刡 ‘搜寻字符串‘ 次数    -i :忽略大小写    -n :输出行号    -v :反向选择,亦即显示出没有 ‘搜寻字符串‘ 内容癿那一行! --color=auto :可以将找刡癿关键词部分加上颜色癿显示!    -A :后面可加数字,为 after 癿意思,除了列出该行外,后续的 n 行也列出;     -B :后面可加数字,为 befer 癿意思,除了列出该行外,前面的 n 行也列出;

GREP supports only the underlying regular notation, and if you want to extend the regular, use Egrep or GREP-E.

The basic regular notation is summarized as follows:

    ^word:查找字符串(word)在行首  grep -n ‘^word‘ filename    word$:  查找字符串(word)在行末  grep -n ‘word$‘ filename    . : 任意字符    \ : 转译    *:前面字符 0 到 任意多个    [] : 字符集合    [n1-n2] : 范围  如[0-9]    [^]: 字符取反,就是不能是里面的字符    \{n,m\}: 出现n到m次

The extension of the regular presentation is summarized as follows:

    +  :一个或者一个以上    ? :零个或者一个    |   : 或    ()  :  群组   egrep -n ‘g(la|oo)d‘ filename  找出 glad 或者 good 两个字符串    ()+:  群组出现一次或者多次

grep also has a lot of advanced usage, please be interested in the replenishment, I only listed the basic common usage.

Shell–grep Common usage

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.