grep 订阅
grep (缩写来自Globally search a Regular Expression and Print)是一种强大的文本搜索工具,它能使用特定模式匹配(包括正则表达式)搜索文本,并默认输出匹配行。Unix的grep家族包括grep、egrep和fgrep。Windows系统下类似命令FINDSTR。 [1] 展开全文
grep (缩写来自Globally search a Regular Expression and Print)是一种强大的文本搜索工具,它能使用特定模式匹配(包括正则表达式)搜索文本,并默认输出匹配行。Unix的grep家族包括grep、egrep和fgrep。Windows系统下类似命令FINDSTR。 [1]
信息
最新版本
3.0 [3]
原作者
Ken Thompson [2]
公开时间
1974 [4]
外文名
Globally search a Regular Expression and Print
GREP基本简介
egrep和fgrep的命令只跟grep有很小不同。egrep和fgrep都是grep的扩展,支持更多的re元字符,fgrep就是fixed grep或fast grep,它们把所有的字母都看作单词,也就是说,正则表达式中的元字符表示回其自身的字面意义,不再特殊。linux使用GNU版本的grep。它功能更强,可以通过-G、-E、-F命令行选项来使用egrep和fgrep的功能。grep的工作方式是这样的,它在一个或多个文件中搜索字符串模板。如果模板包括空格,则必须被引用,模板后的所有字符串被看作文件名。搜索的结果被送到屏幕,不影响原文件内容。grep可用于shell脚本,因为grep通过返回一个状态值来说明搜索的状态,如果模板搜索成功,则返回0,如果搜索不成功,则返回1,如果搜索的文件不存在,则返回2。我们利用这些返回值就可进行一些自动化的文本处理工作。Grep命令中允许指定的串语句是一个规则表达式,这是一种允许使用某些特殊键盘字符的指定字符串的方法,这种方法中的特殊键盘字符可以用于代表其他字符也可以进一步定义模式匹配工作方式。例如:grep ".*hood" essay1。该命令将在文件essay1中搜索,显示出包含带有字符串hood的字的每一行。命令行中的点表示的是hood之前可以有任意字符,星号指的是在字符串之前点号所表示的任意字符可以有任意个(其中的双引号是可有可无的,但是当语句中包含短语或者空格时就必须加双引号)。 [5] 
收起全文
精华内容
参与话题
问答
  • grep

    千次阅读 2016-05-09 13:46:43
    linux grep命令 1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限...

    1.作用
    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。

    2.格式
    grep [options]

    3.主要参数
    [options]主要参数:
    -c:只输出匹配行的计数。
    -i:不区分大小写(只适用于单字符)。
    -h:查询多文件时不显示文件名。
    -l:查询多文件时只输出包含匹配字符的文件名。
    -n:显示匹配行及行号。
    -s:不显示不存在或无匹配文本的错误信息。
    -v:显示不包含匹配文本的所有行。
    pattern正则表达式主要参数:
    \: 忽略正则表达式中特殊字符的原有含义。
    ^:匹配正则表达式的开始行。
    $: 匹配正则表达式的结束行。
    \<:从匹配正则表达式的行开始。
    \>:到匹配正则表达式的行结束。
    [ ]:单个字符,如[A]即A符合要求 。
    [ - ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。
    。:所有的单个字符。
    * :有字符,长度可以为0。

    4.grep命令使用简单实例
    $ grep ‘test’ d*
    显示所有以d开头的文件中包含 test的行。
    $ grep ‘test’ aa bb cc
    显示在aa,bb,cc文件中匹配test的行。
    $ grep ‘[a-z]\{5\}’ aa
    显示所有包含每个字符串至少有5个连续小写字符的字符串的行。
    $ grep ‘w\(es\)t.*\1′ aa
    如果west被匹配,则es就被存储到内存中,并标记为1,然后搜索任意个字符(.*),这些字符后面紧跟着 另外一个es(\1),找到就显示该行。如果用egrep或grep -E,就不用”\”号进行转义,直接写成’w(es)t.*\1′就可以了。

    5.grep命令使用复杂实例
    假设您正在’/usr/src/Linux/Doc’目录下搜索带字符 串’magic’的文件:
    $ grep magic /usr/src/Linux/Doc/*
    sysrq.txt:* How do I enable the magic SysRQ key?
    sysrq.txt:* How do I use the magic SysRQ key?
    其中文件’sysrp.txt’包含该字符串,讨论的是 SysRQ 的功能。
    默认情况下,’grep’只搜索当前目录。如果 此目录下有许多子目录,’grep’会以如下形式列出:
    grep: sound: Is a directory
    这可能会使’grep’ 的输出难于阅读。这里有两种解决的办法:
    明确要求搜索子目录:grep -r
    或忽略子目录:grep -d skip
    如果有很多 输出时,您可以通过管道将其转到’less’上阅读:
    $ grep magic /usr/src/Linux/Documentation/* | less
    这样,您就可以更方便地阅读。

    有一点要注意,您必需提供一个文件过滤方式(搜索全部文件的话用 *)。如果您忘了,’grep’会一直等着,直到该程序被中断。如果您遇到了这样的情况,按 <CTRL c> ,然后再试。

    下面还有一些有意思的命令行参数:
    grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,
    grep -l pattern files :只列出匹配的文件名,
    grep -L pattern files :列出不匹配的文件名,
    grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配’magic’,而不是’magical’),
    grep -C number pattern files :匹配的上下文分别显示[number]行,
    grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行,
    grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。

    grep -n pattern files  即可显示行号信息

    grep -c pattern files  即可查找总行数

    3,常用grep实例

    (1)多个文件查询
        grep "sort" *.doc       #见文件名的匹配

    (2)行匹配:输出匹配行的计数
        grep -c "48" data.doc   #输出文档中含有48字符的行数

    (3)显示匹配行和行数
        grep -n "48" data.doc       #显示所有匹配48的行和行号

    (4)显示非匹配的行
        grep -vn "48" data.doc      #输出所有不包含48的行

    (4)显示非匹配的行
        grep -vn "48" data.doc      #输出所有不包含48的行

    (5)大小写敏感
        grep -i "ab" data.doc       #输出所有含有ab或Ab的字符串的行

    4, 正则表达式的应用

    (1)正则表达式的应用 (注意:最好把正则表达式用单引号括起来)
        grep '[239].' data.doc      #输出所有含有以2,3或9开头的,并且是两个数字的行

    (2)不匹配测试
        grep '^[^48]' data.doc      #不匹配行首是48的行

    (3)使用扩展模式匹配
        grep -E '219|216' data.doc

    (4) ...
        这需要在实践中不断应用和总结,熟练掌握正则表达式。

    5, 使用类名
    可以使用国际模式匹配的类名:
    [[:upper:]]   [A-Z]
    [[:lower:]]   [a-z]
    [[:digit:]]   [0-9]
    [[:alnum:]]   [0-9a-zA-Z]
    [[:space:]]   空格或tab
    [[:alpha:]]   [a-zA-Z]

    (1)使用
        grep '5[[:upper:]][[:upper:]]' data.doc     #查询以5开头以两个大写字母结尾的行

    明确要求搜索子目录:grep -r 或忽略子目录:grep -d skip 

    grep -i pattern files :不区分大小写地搜索。默认情况区分大小写, 
    grep -l pattern files :只列出匹配的文件名, 
    grep -L pattern files :列出不匹配的文件名, 
    grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配‘magic’,而不是‘magical’), 
    grep -C number pattern files :匹配的上下文分别显示[number]行, 
    grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行, 
    grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。

    grep man * 会匹配 ‘Batman’、‘manic’、‘man’等, 
    grep '/<man' * 匹配‘manic’和‘man’,但不是‘Batman’, 
    grep '/<man/>' 只匹配‘man’,而不是‘Batman’或‘manic’等其他的字符串。 
    '^':指匹配的字符串在行首, 
    '$':指匹配的字符串在行尾, 


    展开全文
  • Grep

    2015-05-10 09:38:14
    grep简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。Unix的grep家族...
    1. grep简介

    grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。Unix的grep家族包括grep、egrep和fgrep。egrep和fgrep的命令只跟grep有很小不同。egrep是grep的扩展,支持更多的re元字符, fgrep就是fixed grep或fast grep,它们把所有的字母都看作单词,也就是说,正则表达式中的元字符表示回其自身的字面意义,不再特殊。linux使用GNU版本的grep。它功能更强,可以通过-G、-E、-F命令行选项来使用egrep和fgrep的功能。
    grep的工作方式是这样的,它在一个或多个文件中搜索字符串模板。如果模板包括空格,则必须被引用,模板后的所有字符串被看作文件名。搜索的结果被送到屏幕,不影响原文件内容。
    grep可用于shell脚本,因为grep通过返回一个状态值来说明搜索的状态,如果模板搜索成功,则返回0,如果搜索不成功,则返回1,如果搜索的文件不存在,则返回2。我们利用这些返回值就可进行一些自动化的文本处理工作。
    2. grep正则表达式元字符集(基本集)

    ^
    锚定行的开始 如:’^grep’匹配所有以grep开头的行。
    grep’匹配所有以grep结尾的行。
    .
    匹配一个非换行符的字符 如:’gr.p’匹配gr后接一个任意字符,然后是p。
    *
    匹配零个或多个先前字符 如:’grep’匹配所有一个或多个空格后紧跟grep的行。 .一起用代表任意字符。
    []
    匹配一个指定范围内的字符,如’[Gg]rep’匹配Grep和grep。
    [^]
    匹配一个不在指定范围内的字符,如:’[^A-FH-Z]rep’匹配不包含A-R和T-Z的一个字母开头,紧跟rep的行。
    (..)
    标记匹配字符,如’(love)’,love被标记为1。
    \<
    锚定单词的开始,如:’\

    展开全文
  • grep命令

    千次阅读 2018-05-29 09:37:50
    grep命令

    grep命令

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。
    
    grep可用于shell脚本,因为grep通过返回一个状态值来说明搜索的状态,如果模板搜索成功,则返回0,如果搜索不成功,则返回1,如果搜索的文件不存在,则返回2。我们利用这些返回值就可进行一些自动化的文本处理工作。
    

    一、语法格式:

    grep 选项 参数 文件
    Usage: grep [OPTION]... PATTERN [FILE]...
    

    二、常用命令参数

    -a  不要忽略二进制数据。
    -A  <显示列数> 除了显示符合范本样式的那一行之外,并显示该行之后的内容
    -b  在显示符合范本样式的那一行之外,并显示该行之前的内容
    -c  计算符合范本样式的列数
    -C <显示列数>或-<显示列数>  除了显示符合范本样式的那一列之外,并显示该列之前后的内容。
    -d <进行动作> 当指定要查找的是目录而非文件时,必须使用这项参数,否则grep命令将回报信息并停止动作
    -e <范本样式> 匹配多个样式
    -E 将范本样式为延伸的普通表示法来使用,意味着使用能使用扩展正则表达式
    -f <范本文件> 指定范本文件,其内容有一个或多个范本样式,让grep查找符合范本条件的文件内容,格式为每一列的范本样式
    -F 将范本样式视为固定字符串的列表
    -G 将范本样式视为普通的表示法来使用
    -h 在显示符合范本样式的那一列之前,不标示该列所属的文件名称
    -H 在显示符合范本样式的那一列之前,标示该列的文件名称
    -i 忽略字符大小写
    -l 列出文件内容符合指定的范本样式的文件名称
    -L 列出文件内容不符合指定的范本样式的文件名称
    -n 在显示符合范本样式的那一列之前,标示出该列的编号
    -q 不显示任何信息
    -R/-r 递归查询
    -s 不显示错误信息
    -v 反转查找
    -w 正则匹配只包含完全字符的内容,如roo只匹配roo,不匹配root,roott等
    -x 只显示全列符合的列
    -y 此参数效果跟“-i”相同
    -o 只输出文件中匹配到的部分
    

    三、grep正则表达式

    ^         如:^zhang,表示匹配所有以zhang开头的行。
    $         如:zhang$,表示匹配所有以zhang结尾的行。
    .         匹配一个除换行符之外的字符,如:zha.g,匹配zha后接一个任意字符除换行符之外,然后是g。
    *         匹配零个或多个先前字符,如:*zhang,匹配所有一个或多个字符后面紧跟grep的行。
    .*        匹配任意一个字符出现零次或多次,结合在一起通常表示任意字符
    []        匹配一个指定范围内的字符,如:[zh]ang,匹配zang和hang。
    [^]       匹配一个指定范围内的字符,如:[^A-DG-Z],匹配不包含A-D和G-Z字母开头的行        
    \(..\)    标记匹配字符,如'\(love\)',love被标记为1。 
    \<        锚定单词的开始,如:'\<grep'匹配包含以grep开头的单词的行。    
    \>        锚定单词的结束,如'grep\>'匹配包含以grep结尾的单词的行。    
    \<...\>   匹配只包含括号里面的单词的行,如匹配\<zhangjunchao\>,zhangjunchao110这种不匹配。
    x\{m\}    重复字符x,m次,如:'o\{5\}'匹配包含5个o的行。    
    x\{m,\}   重复字符x,至少m次,如:'o\{5,\}'匹配至少有5个o的行。    
    x\{m,n\}  重复字符x,至少m次,不多于n次,如:'o\{5,10\}'匹配5--10个o的行。   
    \w        匹配文字和数字字符,也就是[A-Za-z0-9],如:'G\w*p'匹配以G后跟零个或多个文字或数字字符,然后是p。   
    \W        \w的反置形式,匹配一个或多个非单词字符,如点号句号等。   
    \b        单词锁定符,如: '\bgrep\b'只匹配grep。  
    

    四、grep命令常见用法

    注:此处所有的grep命令用法我将以a.txt文件里面的内容作为演示的参考

    [root@iZwz9bhan5nqzh979qokrkZ ~]# cat /etc/passwd 
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    adm:x:3:4:adm:/var/adm:/sbin/nologin
    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
    sync:x:5:0:sync:/sbin:/bin/sync
    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    operator:x:11:0:operator:/root:/sbin/nologin
    
    4.1 过滤关键字行
    root@iZwz9bhan5nqzh979qokrkZ ~]# grep root /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator:/root:/sbin/nologin
    
    4.2 过滤关键字行显示关键字在文本的行数
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -n root /etc/passwd
    1:root:x:0:0:root:/root:/bin/bash
    10:operator:x:11:0:operator:/root:/sbin/nologin
    
    4.3 带颜色显示关键字在文本的行数字
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -n root --color /etc/passwd
    1:root:x:0:0:root:/root:/bin/bash
    10:operator:x:11:0:operator:/root:/sbin/nologin
    
    4.4 不区分大小写
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -i root --color /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    operator:x:11:0:operator:/root:/sbin/nologin
    
    4.5 取反
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -v root --color /etc/passwd
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    adm:x:3:4:adm:/var/adm:/sbin/nologin
    lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
    sync:x:5:0:sync:/sbin:/bin/sync
    shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    	
    4.6 显示带关键字的行数
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -c root /etc/passwd
    2
    
    4.7 显示关键字行和后面的2行(总共3行)  After
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -A 2 root /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/sbin/nologin
    daemon:x:2:2:daemon:/sbin:/sbin/nologin
    --
    operator:x:11:0:operator:/root:/sbin/nologin
    games:x:12:100:games:/usr/games:/sbin/nologin
    ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
    
    4.8  显示关键字行和前面的2行  Before
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -B 2 root /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    --
    halt:x:7:0:halt:/sbin:/sbin/halt
    mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    operator:x:11:0:operator:/root:/sbin/nologin
    
    4.9 匹配IP地址
    [root@iZwz9bhan5nqzh979qokrkZ ~]# ifconfig eth0 | grep "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" 
            inet 172.18.108.103  netmask 255.255.240.0  broadcast 172.18.111.255
    [root@iZwz9bhan5nqzh979qokrkZ ~]#  ifconfig eth0 | grep -E "([0-9]{1,3}\.){3}[0-9]"        
            inet 172.18.108.103  netmask 255.255.240.0  broadcast 172.18.111.255   
    注:.有特殊意义,所以需要转义
    
    4.10 将a.txt文件中不包含400的行输入到b.txt文件中
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep '.' a.txt  | grep -Ev "400"  > b.txt
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep '.' a.txt  | grep -Ev "(400|502|110|390)"  > b.txt
    注:多个条件需要用到-E参数
    
    4.11 递归查找
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -R -n --color "Hostname" /usr/local/zabbix
    136:### Option: Hostname
    139:#	Value is acquired from HostnameItem if undefined.
    143:# Hostname=
    145:Hostname=host-39-108-217-12
    
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep -E -R -n --color "(Hostname|Server)" /usr/local/zabbix
    82:### Option: Server
    87:#	Example: Server=127.0.0.1,192.168.1.0/24,::1,2001:db8::/32,zabbix.domain
    91:# Server=
    93:Server=39.108.217.12
    122:### Option: ServerActive
    128:#	Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
    132:# ServerActive=
    134:# ServerActive=127.0.0.1
    136:### Option: Hostname
    139:#	Value is acquired from HostnameItem if undefined.
    143:# Hostname=
    
    注:-n:打印行号  --color:带颜色  -R:递归查询  -E:支持扩展正则
    	
    4.12 选项 -e:匹配多个匹配样式 -o:只输出匹配到的内容
    [root@iZwz9bhan5nqzh979qokrkZ ~]# echo this is a text line | grep -e "is" -e "line" -o
    is
    is
    line
    
    4.13 搜索多个文件并查找匹配文本在哪些文件中:
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep 'zhangjunchao' /root -lr
    /root/b.txt
    /root/a.txt
    
    4.14 在grep搜索结果中包括或者排除指定文件:
    
    只在目录中所有的.php和.html文件中递归搜索字符"main()"
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep "main()" . -r --include *.{php,html}
    
    在搜索结果中排除所有README文件
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep "main()" . -r --exclude "README"
    
    在搜索结果中排除filelist文件列表里的文件
    [root@iZwz9bhan5nqzh979qokrkZ ~]# grep "main()" . -r --exclude-from filelist
    

    五、补充:grep使用多个查询条件?

    1. \ | 符号法
    [root@mail ~]# grep 'usrquota\ |grpquota' /etc/fstab
    
    2. 使用多个-e参数
    netstat -an | grep -e EST -e WAIT
    并列使用多个-e参数可以实现或条件
    	
    3. 使用扩展-E
    netstat -an | grep -E "ESTABLISHED|WAIT"
    此处的 -E 是大写 ,匹配条件一定要加 引号
    

    六、grep -q用法
    grep -q用于if逻辑判断
    https://blog.csdn.net/sim120/article/details/10151327

    总结:grep命令其实是一个很强大的命令,工作中经常会用到,所以有必要总结一下,当然gerp命令的用法肯定不只是这么多,还有很多其他的用法,在这里就不一一列举了,这里展示的这些只是我工作中用到的一些,大家就各自脑补吧!

    展开全文
  • **process_num=`ps -ef |grep "$1" |grep -v "grep" |wc -l` echo "process_num :" $process_num** if [ $process_num -eq 1 ]; then return 0 else return 1 fi } while [ 1 ] ; do ...
  • grep --help 可以查看到grep的中文用法介绍,显示如下。如果是使用man grep,显示的是英文的介绍。 用法: grep [选项]... PATTERN [FILE]... 在每个 FILE 或是标准输入中查找 PATTERN。 默认的 PATTERN 是一个...

    通过在linux命令行终端中输入

    grep --help

    可以查看到grep的中文用法介绍,显示如下。如果是使用man grep,显示的是英文的介绍。

    用法: grep [选项]... PATTERN [FILE]...
    在每个 FILE 或是标准输入中查找 PATTERN。
    默认的 PATTERN 是一个基本正则表达式(缩写为 BRE)。
    例如: grep -i 'hello world' menu.h main.c

    正则表达式选择与解释:
      -E, --extended-regexp     PATTERN 是一个可扩展的正则表达式(缩写为 ERE)
      -F, --fixed-strings       PATTERN 是一组由断行符分隔的定长字符串。
      -G, --basic-regexp        PATTERN 是一个基本正则表达式(缩写为 BRE)
      -P, --perl-regexp         PATTERN 是一个 Perl 正则表达式
      -e, --regexp=PATTERN      用 PATTERN 来进行匹配操作
      -f, --file=FILE           从 FILE 中取得 PATTERN
      -i, --ignore-case         忽略大小写
      -w, --word-regexp         强制 PATTERN 仅完全匹配字词
      -x, --line-regexp         强制 PATTERN 仅完全匹配一行
      -z, --null-data           一个 0 字节的数据行,但不是空行

    杂项:
      -s, --no-messages         不显示错误信息
      -v, --invert-match        选中不匹配的行
      -V, --version             显示版本信息并退出
          --help                显示此帮助并退出
          --mmap                忽略向后兼容性

    输出控制:
      -m, --max-count=NUM       NUM 次匹配后停止
      -b, --byte-offset         输出行的同时打印字节偏移
      -n, --line-number         输出行的同时打印行号
          --line-buffered       每行输出清空
      -H, --with-filename       为每一匹配项打印文件名
      -h, --no-filename         输出时不显示文件名前缀
          --label=LABEL         标准输入将LABEL 打印为文件名
      -o, --only-matching       只显示一行中匹配PATTERN 的部分
      -q, --quiet, --silent     不显示所有输出
          --binary-files=TYPE   假定二进制文件的TYPE 类型;
                                TYPE 可以是`binary', `text', 或`without-match'
      -a, --text                等同于 --binary-files=text
      -I                        等同于 --binary-files=without-match
      -d, --directories=ACTION  操作目录的方式;
                                ACTION 可以是`read', `recurse',或`skip'
      -D, --devices=ACTION      操作设备、先入先出队列、套接字的方式;
                                ACTION 可以是`read'或`skip'
      -R, -r, --recursive       等同于 --directories=recurse
          --include=FILE_PATTERN  只查找匹配FILE_PATTERN 的文件
          --exclude=FILE_PATTERN  跳过匹配FILE_PATTERN 的文件和目录
          --exclude-from=FILE   跳过所有除FILE 以外的文件
          --exclude-dir=PATTERN  跳过所有匹配PATTERN 的目录。
      -L, --files-without-match  只打印不匹配FILEs 的文件名
      -l, --files-with-matches  只打印匹配FILES 的文件名
      -c, --count               只打印每个FILE 中的匹配行数目
      -T, --initial-tab         行首tabs 分隔(如有必要)
      -Z, --null                在FILE 文件最后打印空字符

    文件控制:
      -B, --before-context=NUM  打印以文本起始的NUM 行
      -A, --after-context=NUM   打印以文本结尾的NUM 行
      -C, --context=NUM         打印输出文本NUM 行
      -NUM                      等同于 --context=NUM
          --color[=WHEN],
          --colour[=WHEN]       使用标志高亮匹配字串;
                                WHEN 可以是`always', `never'或`auto'
      -U, --binary              不要清除行尾的CR 字符(MSDOS 模式)
      -u, --unix-byte-offsets   当CR 字符不存在,报告字节偏移(MSDOS 模式)

    ‘egrep’即‘grep -E’。‘fgrep’即‘grep -F’。
    直接使用‘egrep’或是‘fgrep’均已不可行了。
    不带 FILE 参数,或是 FILE 为 -,将读取标准输入。如果少于两个 FILE 参数
    就要默认使用 -h 参数。如果选中任意一行,那退出状态为 0,否则为 1;
    如果有错误产生,且未指定 -q 参数,那退出状态为 2。

    请将错误报告给: bug-grep@gnu.org
    GNU Grep 主页: <http://www.gnu.org/software/grep/>

    GNU 软件的通用帮助: <http://www.gnu.org/gethelp/>

    ---------------------------------------------------------------------------------------------------------------------------------------------

    下面是通过man grep查看到的介绍,要比上面用grep --help显示的详细。

    GREP(1)                                                                                                                                              GREP(1)



    NAME
           grep, egrep, fgrep, rgrep - print lines matching a pattern

    SYNOPSIS
           grep [OPTIONS] PATTERN [FILE...]
           grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

    DESCRIPTION
           grep  searches  the  named  input  FILEs  (or  standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines
           containing a match to the given PATTERN.  By default, grep prints the matching lines.

           In addition, three variant programs egrep, fgrep and rgrep are available.  egrep is the same as grep -E.  fgrep is the same as grep -F.  rgrep is the
           same as grep -r.  Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run
           unmodified.

    OPTIONS
       Generic Program Information
           --help Print a usage message briefly summarizing these command-line options and the bug-reporting address, then exit.

           -V, --version
                  Print the version number of grep to the standard output stream.  This version number should be included in all bug reports (see below).

       Matcher Selection
           -E, --extended-regexp
                  Interpret PATTERN as an extended regular expression (ERE, see below).  (-E is specified by POSIX.)

           -F, --fixed-strings
                  Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.  (-F is specified by POSIX.)

           -G, --basic-regexp
                  Interpret PATTERN as a basic regular expression (BRE, see below).  This is the default.

           -P, --perl-regexp
                  Interpret PATTERN as a Perl regular expression.  This is highly experimental and grep -P may warn of unimplemented features.

       Matching Control
           -e PATTERN, --regexp=PATTERN
                  Use PATTERN as the pattern.  This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen  (-).   (-e
                  is specified by POSIX.)

           -f FILE, --file=FILE
                  Obtain patterns from FILE, one per line.  The empty file contains zero patterns, and therefore matches nothing.  (-f is specified by POSIX.)

           -i, --ignore-case
                  Ignore case distinctions in both the PATTERN and the input files.  (-i is specified by POSIX.)

           -v, --invert-match
                  Invert the sense of matching, to select non-matching lines.  (-v is specified by POSIX.)

           -w, --word-regexp
                  Select  only those lines containing matches that form whole words.  The test is that the matching substring must either be at the beginning of
                  the line, or preceded by a non-word constituent character.  Similarly, it must be either at the end of the line  or  followed  by  a  non-word
                  constituent character.  Word-constituent characters are letters, digits, and the underscore.

           -x, --line-regexp
                  Select only those matches that exactly match the whole line.  (-x is specified by POSIX.)

           -y     Obsolete synonym for -i.

       General Output Control
           -c, --count
                  Suppress  normal  output;  instead print a count of matching lines for each input file.  With the -v, --invert-match option (see below), count
                  non-matching lines.  (-c is specified by POSIX.)

           --color[=WHEN], --colour[=WHEN]
                  Surround the matched (non-empty) strings, matching lines, context lines, file names, line numbers, byte offsets, and  separators  (for  fields
                  and  groups  of  context  lines)  with  escape  sequences to display them in color on the terminal.  The colors are defined by the environment
                  variable GREP_COLORS.  The deprecated environment variable GREP_COLOR is still supported, but its setting does not  have  priority.   WHEN  is
                  never, always, or auto.

           -L, --files-without-match
                  Suppress  normal  output;  instead print the name of each input file from which no output would normally have been printed.  The scanning will
                  stop on the first match.

           -l, --files-with-matches
                  Suppress normal output; instead print the name of each input file from which output would normally have been printed.  The scanning will  stop
                  on the first match.  (-l is specified by POSIX.)

           -m NUM, --max-count=NUM
                  Stop  reading  a  file  after NUM matching lines.  If the input is standard input from a regular file, and NUM matching lines are output, grep
                  ensures that the standard input is positioned to just after the last matching line before exiting, regardless  of  the  presence  of  trailing
                  context  lines.  This enables a calling process to resume a search.  When grep stops after NUM matching lines, it outputs any trailing context
                  lines.  When the -c or --count option is also used, grep does not output a count greater than NUM.  When the -v or  --invert-match  option  is
                  also used, grep stops after outputting NUM non-matching lines.

           -o, --only-matching
                  Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

           -q, --quiet, --silent
                  Quiet;  do  not  write  anything  to standard output.  Exit immediately with zero status if any match is found, even if an error was detected.
                  Also see the -s or --no-messages option.  (-q is specified by POSIX.)

           -s, --no-messages
                  Suppress error messages about nonexistent or unreadable files.  Portability note: unlike GNU grep, 7th Edition Unix grep did  not  conform  to
                  POSIX, because it lacked -q and its -s option behaved like GNU grep's -q option.  USG-style grep also lacked -q but its -s option behaved like
                  GNU grep.  Portable shell scripts should avoid both -q and -s and should redirect standard and error output  to  /dev/null  instead.   (-s  is
                  specified by POSIX.)

       Output Line Prefix Control
           -b, --byte-offset
                  Print the 0-based byte offset within the input file before each line of output.  If -o (--only-matching) is specified, print the offset of the
                  matching part itself.

           -H, --with-filename
                  Print the file name for each match.  This is the default when there is more than one file to search.

           -h, --no-filename
                  Suppress the prefixing of file names on output.  This is the default when there is only one file (or only standard input) to search.

           --label=LABEL
                  Display input actually coming from standard input as input coming from file LABEL.  This is especially useful  when  implementing  tools  like
                  zgrep, e.g., gzip -cd foo.gz | grep --label=foo -H something.  See also the -H option.

           -n, --line-number
                  Prefix each line of output with the 1-based line number within its input file.  (-n is specified by POSIX.)

           -T, --initial-tab
                  Make sure that the first character of actual line content lies on a tab stop, so that the alignment of tabs looks normal.  This is useful with
                  options that prefix their output to the actual content: -H,-n, and -b.  In order to improve the probability that lines from a single file will
                  all start at the same column, this also causes the line number and byte offset (if present) to be printed in a minimum size field width.

           -u, --unix-byte-offsets
                  Report  Unix-style  byte  offsets.   This  switch causes grep to report byte offsets as if the file were a Unix-style text file, i.e., with CR
                  characters stripped off.  This will produce results identical to running grep on a Unix machine.  This option has no effect unless  -b  option
                  is also used; it has no effect on platforms other than MS-DOS and MS-Windows.

           -Z, --null
                  Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.  For example, grep -lZ outputs a zero
                  byte after each file name instead of the usual newline.  This option makes the  output  unambiguous,  even  in  the  presence  of  file  names
                  containing  unusual  characters  like  newlines.   This  option can be used with commands like find -print0, perl -0, sort -z, and xargs -0 to
                  process arbitrary file names, even those that contain newline characters.

       Context Line Control
           -A NUM, --after-context=NUM
                  Print NUM lines of trailing context after matching lines.  Places a line containing a  group  separator  (--)  between  contiguous  groups  of
                  matches.  With the -o or --only-matching option, this has no effect and a warning is given.

           -B NUM, --before-context=NUM
                  Print  NUM  lines  of  leading  context  before  matching lines.  Places a line containing a group separator (--) between contiguous groups of
                  matches.  With the -o or --only-matching option, this has no effect and a warning is given.

           -C NUM, -NUM, --context=NUM
                  Print NUM lines of output context.  Places a line containing a group separator (--) between contiguous groups of  matches.   With  the  -o  or
                  --only-matching option, this has no effect and a warning is given.

       File and Directory Selection
           -a, --text
                  Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

           --binary-files=TYPE
                  If  the  first  few  bytes  of  a file indicate that the file contains binary data, assume that the file is of type TYPE.  By default, TYPE is
                  binary, and grep normally outputs either a one-line message saying that a binary file matches, or no message if there is no match.  If TYPE is
                  without-match,  grep assumes that a binary file does not match; this is equivalent to the -I option.  If TYPE is text, grep processes a binary
                  file as if it were text; this is equivalent to the -a option.  Warning: grep --binary-files=text might output binary garbage, which  can  have
                  nasty side effects if the output is a terminal and if the terminal driver interprets some of it as commands.

           -D ACTION, --devices=ACTION
                  If an input file is a device, FIFO or socket, use ACTION to process it.  By default, ACTION is read, which means that devices are read just as
                  if they were ordinary files.  If ACTION is skip, devices are silently skipped.

           -d ACTION, --directories=ACTION
                  If an input file is a directory, use ACTION to process it.  By default, ACTION is read, which means that directories are read just as if  they
                  were  ordinary  files.  If ACTION is skip, directories are silently skipped.  If ACTION is recurse, grep reads all files under each directory,
                  recursively; this is equivalent to the -r option.

           --exclude=GLOB
                  Skip files whose base name matches GLOB (using wildcard matching).  A file-name glob can use *, ?, and [...]  as wildcards, and \ to  quote  a
                  wildcard or backslash character literally.

           --exclude-from=FILE
                  Skip files whose base name matches any of the file-name globs read from FILE (using wildcard matching as described under --exclude).

           --exclude-dir=DIR
                  Exclude directories matching the pattern DIR from recursive searches.

           -I     Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.

           --include=GLOB
                  Search only files whose base name matches GLOB (using wildcard matching as described under --exclude).

           -R, -r, --recursive
                  Read all files under each directory, recursively; this is equivalent to the -d recurse option.

       Other Options
           --line-buffered
                  Use line buffering on output.  This can cause a performance penalty.

           --mmap If  possible, use the mmap(2) system call to read input, instead of the default read(2) system call.  In some situations, --mmap yields better
                  performance.  However, --mmap can cause undefined behavior (including core dumps) if an input file shrinks while grep is operating, or  if  an
                  I/O error occurs.

           -U, --binary
                  Treat the file(s) as binary.  By default, under MS-DOS and MS-Windows, grep guesses the file type by looking at the contents of the first 32KB
                  read from the file.  If grep decides the file is a text file, it strips the CR characters from the original file  contents  (to  make  regular
                  expressions  with  ^  and  $ work correctly).  Specifying -U overrules this guesswork, causing all files to be read and passed to the matching
                  mechanism verbatim; if the file is a text file with CR/LF pairs at the end of each line, this will cause some  regular  expressions  to  fail.
                  This option has no effect on platforms other than MS-DOS and MS-Windows.

           -z, --null-data
                  Treat  the  input  as  a  set  of lines, each terminated by a zero byte (the ASCII NUL character) instead of a newline.  Like the -Z or --null
                  option, this option can be used with commands like sort -z to process arbitrary file names.

    REGULAR EXPRESSIONS
           A regular expression is a pattern that describes a set of strings.  Regular expressions are constructed analogously  to  arithmetic  expressions,  by
           using various operators to combine smaller expressions.

           grep  understands  three  different  versions  of  regular  expression syntax: “basic,” “extended” and “perl.” In GNU grep, there is no difference in
           available functionality between basic and extended syntaxes.  In other implementations, basic regular expressions are less powerful.   The  following
           description  applies  to extended regular expressions; differences for basic regular expressions are summarized afterwards.  Perl regular expressions
           give additional functionality, and are documented in pcresyntax(3) and pcrepattern(3), but may not be available on every system.

           The fundamental building blocks are the regular expressions that match a single character.  Most characters, including all letters  and  digits,  are
           regular expressions that match themselves.  Any meta-character with special meaning may be quoted by preceding it with a backslash.

           The period . matches any single character.

       Character Classes and Bracket Expressions
           A  bracket  expression is a list of characters enclosed by [ and ].  It matches any single character in that list; if the first character of the list
           is the caret ^ then it matches any character not in the list.  For example, the regular expression [0123456789] matches any single digit.

           Within a bracket expression, a range expression consists of two characters separated by a hyphen.  It matches any single character that sorts between
           the two characters, inclusive, using the locale's collating sequence and character set.  For example, in the default C locale, [a-d] is equivalent to
           [abcd].  Many locales sort characters in dictionary order, and in these locales [a-d] is typically not equivalent to [abcd]; it might  be  equivalent
           to  [aBbCcDd],  for  example.   To  obtain  the  traditional  interpretation  of  bracket expressions, you can use the C locale by setting the LC_ALL
           environment variable to the value C.

           Finally, certain named classes of characters are predefined within bracket expressions, as follows.  Their names are self explanatory, and  they  are
           [:alnum:],  [:alpha:],  [:cntrl:],  [:digit:],  [:graph:],  [:lower:],  [:print:],  [:punct:],  [:space:],  [:upper:],  and [:xdigit:].  For example,
           [[:alnum:]] means [0-9A-Za-z], except the latter form depends upon the C locale and the ASCII character encoding, whereas the former  is  independent
           of  locale  and  character set.  (Note that the brackets in these class names are part of the symbolic names, and must be included in addition to the
           brackets delimiting the bracket expression.)  Most meta-characters lose their special meaning inside bracket expressions.  To  include  a  literal  ]
           place it first in the list.  Similarly, to include a literal ^ place it anywhere but first.  Finally, to include a literal - place it last.

       Anchoring
           The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of a line.

       The Backslash Character and Special Expressions
           The  symbols \< and \> respectively match the empty string at the beginning and end of a word.  The symbol \b matches the empty string at the edge of
           a word, and \B matches the empty string provided it's not at the edge of a word.  The symbol \w is a synonym for [[:alnum:]] and \W is a synonym  for
           [^[:alnum:]].

       Repetition
           A regular expression may be followed by one of several repetition operators:
           ?      The preceding item is optional and matched at most once.
           *      The preceding item will be matched zero or more times.
           +      The preceding item will be matched one or more times.
           {n}    The preceding item is matched exactly n times.
           {n,}   The preceding item is matched n or more times.
           {,m}   The preceding item is matched at most m times.
           {n,m}  The preceding item is matched at least n times, but not more than m times.

       Concatenation
           Two  regular  expressions  may  be  concatenated;  the  resulting  regular  expression matches any string formed by concatenating two substrings that
           respectively match the concatenated expressions.

       Alternation
           Two regular expressions may be joined by the infix operator |; the  resulting  regular  expression  matches  any  string  matching  either  alternate
           expression.

       Precedence
           Repetition  takes  precedence over concatenation, which in turn takes precedence over alternation.  A whole expression may be enclosed in parentheses
           to override these precedence rules and form a subexpression.

       Back References and Subexpressions
           The back-reference \n, where n is a single digit, matches the substring previously matched by the nth  parenthesized  subexpression  of  the  regular
           expression.

       Basic vs Extended Regular Expressions
           In  basic  regular  expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{,
           \|, \(, and \).

           Traditional egrep did not support the { meta-character, and some egrep implementations support \{ instead, so portable  scripts  should  avoid  {  in
           grep -E patterns and should use [{] to match a literal {.

           GNU  grep -E  attempts  to support traditional usage by assuming that { is not special if it would be the start of an invalid interval specification.
           For example, the command grep -E '{1' searches for the two-character string {1 instead of  reporting  a  syntax  error  in  the  regular  expression.
           POSIX.2 allows this behavior as an extension, but portable scripts should avoid it.

    ENVIRONMENT VARIABLES
           The behavior of grep is affected by the following environment variables.

           The  locale  for  category  LC_foo is specified by examining the three environment variables LC_ALL, LC_foo, LANG, in that order.  The first of these
           variables that is set specifies the locale.  For example, if LC_ALL is not set, but LC_MESSAGES is set to pt_BR, then the Brazilian Portuguese locale
           is  used  for the LC_MESSAGES category.  The C locale is used if none of these environment variables are set, if the locale catalog is not installed,
           or if grep was not compiled with national language support (NLS).

           GREP_OPTIONS
                  This variable specifies default options to be placed  in  front  of  any  explicit  options.   For  example,  if  GREP_OPTIONS  is  '--binary-
                  files=without-match  --directories=skip',  grep  behaves  as  if  the two options --binary-files=without-match and --directories=skip had been
                  specified before any explicit options.  Option specifications are separated by whitespace.  A backslash escapes the next character, so it  can
                  be used to specify an option containing whitespace or a backslash.

           GREP_COLOR
                  This  variable specifies the color used to highlight matched (non-empty) text.  It is deprecated in favor of GREP_COLORS, but still supported.
                  The mt, ms, and mc capabilities of GREP_COLORS have priority over it.  It can only specify the color used to highlight the matching  non-empty
                  text  in  any matching line (a selected line when the -v command-line option is omitted, or a context line when -v is specified).  The default
                  is 01;31, which means a bold red foreground text on the terminal's default background.

           GREP_COLORS
                  Specifies the colors and other attributes used to highlight various parts of the output.  Its value is a colon-separated list of  capabilities
                  that  defaults  to ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36 with the rv and ne boolean capabilities omitted (i.e., false).  Supported
                  capabilities are as follows.

                  sl=    SGR substring for whole selected lines (i.e., matching lines when the -v command-line option is omitted, or non-matching lines when  -v
                         is  specified).  If however the boolean rv capability and the -v command-line option are both specified, it applies to context matching
                         lines instead.  The default is empty (i.e., the terminal's default color pair).

                  cx=    SGR substring for whole context lines (i.e., non-matching lines when the -v command-line option is omitted, or matching lines  when  -v
                         is  specified).   If  however  the boolean rv capability and the -v command-line option are both specified, it applies to selected non-
                         matching lines instead.  The default is empty (i.e., the terminal's default color pair).

                  rv     Boolean value that reverses (swaps) the meanings of the sl= and cx= capabilities when the -v command-line  option  is  specified.   The
                         default is false (i.e., the capability is omitted).

                  mt=01;31
                         SGR  substring for matching non-empty text in any matching line (i.e., a selected line when the -v command-line option is omitted, or a
                         context line when -v is specified).  Setting this is equivalent to setting both ms= and mc= at once to the same value.  The default  is
                         a bold red text foreground over the current line background.

                  ms=01;31
                         SGR  substring  for  matching  non-empty text in a selected line.  (This is only used when the -v command-line option is omitted.)  The
                         effect of the sl= (or cx= if rv) capability remains active when this kicks in.  The default is a bold  red  text  foreground  over  the
                         current line background.

                  mc=01;31
                         SGR  substring  for  matching non-empty text in a context line.  (This is only used when the -v command-line option is specified.)  The
                         effect of the cx= (or sl= if rv) capability remains active when this kicks in.  The default is a bold  red  text  foreground  over  the
                         current line background.

                  fn=35  SGR  substring  for  file  names  prefixing  any  content  line.   The default is a magenta text foreground over the terminal's default
                         background.

                  ln=32  SGR substring for line numbers prefixing any content line.  The default  is  a  green  text  foreground  over  the  terminal's  default
                         background.

                  bn=32  SGR  substring  for  byte  offsets  prefixing  any  content  line.   The default is a green text foreground over the terminal's default
                         background.

                  se=36  SGR substring for separators that are inserted between selected line fields (:), between context line fields, (-), and  between  groups
                         of  adjacent  lines  when  nonzero  context  is  specified  (--).   The  default  is a cyan text foreground over the terminal's default
                         background.

                  ne     Boolean value that prevents clearing to the end of line using Erase in Line (EL) to Right (\33[K) each  time  a  colorized  item  ends.
                         This  is  needed  on  terminals on which EL is not supported.  It is otherwise useful on terminals for which the back_color_erase (bce)
                         boolean terminfo capability does not apply, when the chosen highlight colors do not affect the background, or when EL is  too  slow  or
                         causes too much flicker.  The default is false (i.e., the capability is omitted).

                  Note that boolean capabilities have no =...  part.  They are omitted (i.e., false) by default and become true when specified.

                  See  the  Select Graphic Rendition (SGR) section in the documentation of the text terminal that is used for permitted values and their meaning
                  as character attributes.  These substring values are integers in decimal representation and can be concatenated with semicolons.   grep  takes
                  care  of  assembling  the result into a complete SGR sequence (\33[...m).  Common values to concatenate include 1 for bold, 4 for underline, 5
                  for blink, 7 for inverse, 39 for default foreground color, 30 to 37 for foreground colors, 90 to  97  for  16-color  mode  foreground  colors,
                  38;5;0 to 38;5;255 for 88-color and 256-color modes foreground colors, 49 for default background color, 40 to 47 for background colors, 100 to
                  107 for 16-color mode background colors, and 48;5;0 to 48;5;255 for 88-color and 256-color modes background colors.

           LC_ALL, LC_COLLATE, LANG
                  These variables specify the locale for the LC_COLLATE category, which determines the collating sequence used to  interpret  range  expressions
                  like [a-z].

           LC_ALL, LC_CTYPE, LANG
                  These variables specify the locale for the LC_CTYPE category, which determines the type of characters, e.g., which characters are whitespace.

           LC_ALL, LC_MESSAGES, LANG
                  These  variables  specify  the  locale for the LC_MESSAGES category, which determines the language that grep uses for messages.  The default C
                  locale uses American English messages.

           POSIXLY_CORRECT
                  If set, grep behaves as POSIX.2 requires; otherwise, grep behaves more like other GNU programs.  POSIX.2 requires  that  options  that  follow
                  file  names  must be treated as file names; by default, such options are permuted to the front of the operand list and are treated as options.
                  Also, POSIX.2 requires that unrecognized options be diagnosed as “illegal”, but since they are not really against the law the  default  is  to
                  diagnose them as “invalid”.  POSIXLY_CORRECT also disables _N_GNU_nonoption_argv_flags_, described below.

           _N_GNU_nonoption_argv_flags_
                  (Here  N  is  grep's  numeric process ID.)  If the ith character of this environment variable's value is 1, do not consider the ith operand of
                  grep to be an option, even if it appears to be one.  A shell can put this variable in the environment for each  command  it  runs,  specifying
                  which  operands  are  the  results of file name wildcard expansion and therefore should not be treated as options.  This behavior is available
                  only with the GNU C library, and only when POSIXLY_CORRECT is not set.

    EXIT STATUS
           The exit status is 0 if selected lines are found, and 1 if not found.  If an error occurred the exit status is 2.  (Note: POSIX error  handling  code
           should check for '2' or greater.)

    COPYRIGHT
           Copyright 1998-2000, 2002, 2005-2010 Free Software Foundation, Inc.

           This  is  free  software;  see  the  source  for  copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
           PURPOSE.

    BUGS
       Reporting Bugs
           Email bug reports to <bug-grep@gnu.org>, a mailing list whose web page  is  <http://lists.gnu.org/mailman/listinfo/bug-grep>.   grep's  Savannah  bug
           tracker is located at <http://savannah.gnu.org/bugs/?group=grep>.

       Known Bugs
           Large  repetition counts in the {n,m} construct may cause grep to use lots of memory.  In addition, certain other obscure regular expressions require
           exponential time and space, and may cause grep to run out of memory.

           Back-references are very slow, and may require exponential time.

    SEE ALSO
       Regular Manual Pages
           awk(1), cmp(1), diff(1), find(1), gzip(1), perl(1), sed(1), sort(1), xargs(1), zgrep(1), mmap(2), read(2),  pcre(3),  pcresyntax(3),  pcrepattern(3),
           terminfo(5), glob(7), regex(7).

       POSIX Programmer's Manual Page
           grep(1p).

       TeXinfo Documentation
           The full documentation for grep is maintained as a TeXinfo manual.  If the info and grep programs are properly installed at your site, the command

                  info grep

           should give you access to the complete manual.

    NOTES
           GNU's not Unix, but Unix is a beast; its plural form is Unixen.



    User Commands                                                          GNU grep 2.6.3                                                                GREP(1)
    展开全文
  • grep 命令

    千次阅读 2014-01-16 16:20:42
    一、grep 命令的一般格式  grep [option] pattern file  用于查找文件中字符串 二、grep option选项,如下图   三、pattern  为正则表达式,正则表达式分为普通字符与特殊字符(元字符),元字符分为基本的...
  • grep使用

    2013-11-14 20:47:59
    常用的 grep 选项有:  -c 只输出匹配行的个数。  -i 不区分大小写(只适用于单字符)。  -h 查询多文件时不显示文件名。  -l 查询多文件时只输出包含匹配字符的文件名。  -n 显示匹配行及行号。  -s 不...
  • grep -i 命令提取文件中关键字所在行时,当关键字为负数时报错。 匹配的关键词为正数时是OK的, ``` $ grep -i "1.50513e-01," file.txt cd3("cd3","coefficienct", 1.50513e-01, -4, 4); ``` 但...
  • grep -v grep

    千次阅读 2018-01-08 09:30:41
    1.grep 是查找含有指定文本行的意思,比如grep test 就是查找含有test的文本的行 2.grep -v 是反向查找的意思,比如 grep -v grep 就是查找不含有 grep 字段的行 我们想要找出哪个进程的id 可以使用...
  • Linux中grep命令详解

    万次阅读 多人点赞 2019-04-07 21:48:40
    grep命令 grep 1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限...
  • Linux grep -v 命令排除输出

    万次阅读 2019-05-24 13:53:02
    有时候,我们在线上查日志定位问题的时候,经常会使用cat xxxx.log |grep yyyy命令,如果grep的时候,想排除某些字段,那么可以如下操作: cat test.log | grep "login"|grep -v "deviceType" 上面的命令的意思是:...
  • 通过orderid在20_$date1.data这个文件中查找包含orderid行,通过/dev/null 2>&1返回值判断是否存在此orderid行,再根据if else对包含该orderid行进行更改,可是 执行的时候总是返回 1 is not exist(我用grep单纯...
  • grep的用法

    万次阅读 2015-10-23 17:22:32
     语 法:grep [-abcEFGhHilLnqrsvVwxy] [-A][-B][-C][-d][-e][-f][--help][范本样式][文件或目录...] 如果要在一个或几个文本文件中查找一字符串,可以使用‘grep’命令。 grep pattern filename grep ...
  • Linux grep 命令

    千次阅读 2015-07-13 10:18:17
    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。 grep的工作...
  • linux grep命令

    2014-01-23 14:37:01
    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。 2.格式 grep...
  • Linux 使用grep筛选多个条件

    万次阅读 2018-07-04 10:54:42
    !!!! grep 同时满足多个关键字和满足任意关键字 ① grep -E "word1|word2|word3" file....② grep word1 file.txt | grep word2 |grep word3 必须同时满足三个条件(word1、word2和word3)才匹配。 3.统计符合...
  • |grep "" |grep "" 这两个放在一起是从前边的结果中查找符合后边grep的信息 只能查一行的内容 |grep -C30 "" |grep "" 预想的结果:从前一个查询结果的前后30行中查询符合另一个grep的结果 ...
  • <p>I analyze stream from multicast address. Output of the command looks ... I found how <code>grep -oP '(?<=Bitrate: )[0-9]+'</code> so I get "8241" but i need both variables i one step. </div>
  • Ubuntu学习之grep

    多人点赞 2015-01-04 19:02:13
    今天学习grep命令运行时,grep出去等待状态的原因如下: 如果预料到有许多输出,您可以通过 管道 将其转到‘less’上阅读 $ grep magic /usr/src/linux/Documentation/* | less 这样,您就可以更方便地阅读。 有...
  • 今天我用grep写shell的时候,发现一个很奇怪的问题,当我用命令grep搜索数据时,返回的多行数据时是按每行显示的,但是当我在shell里把这个搜索命令赋值到变量后,输出这个变量,就变成一行输出了,百度也查不到,有...
  • grep 匹配中文的问题

    2017-03-14 08:18:58
    grep -c [^\u4e00-\u9fa5] 20150420102314.006_utf8.txt 或 grep -c [^\x00-\xff] 20150420102314.006.txt 的结果都是151 然而20150420102314.006.txt的行数是151行,意思是全部匹配了 但是用Notepad++或者gedit用...
  • ps -ef|grep cpu|grep -v grep   1、场景 在一个Linux机器上起了很多个cpu.sh的脚本,如下图,想一次性把他们kill掉 2、方法 2.1去除grep cpu 上图中可以看到最后一个pid为22603的进程是grep cpu进程,并非...

空空如也

1 2 3 4 5 ... 20
收藏数 133,626
精华内容 53,450
关键字:

grep