grep -E == egrep

[root@wangshaojun ~]# grep --color 'r\?o' 1.txt == egrep --color 'r?o' 1.txt ^C
[root@wangshaojun ~]# egrep --color 'r?o' 1.txt

root:x:0:0:root:/root:/bin/bash   //roo中ro匹配一次 o匹配一次
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

.......

特殊符号‘+’  表示1个或多个+号前面的字符

[root@wangshaojun ~]# egrep --color 'r+o' 1.txt

[root@wangshaojun ~]# grep --color -E 'r+o' 1.txt

[root@wangshaojun ~]# grep --color 'r\+o' 1.txt

root:x:0:0:root:/root:/bin/bash
syrrrrrrrrronc:x:5:0:sync:/sbin:/bin/sync
halt:x:7:rro0:halt:/sbin:/sbin/halt
operator:x:11:0:operator:/root:/sbin/nologin

.....

////////////////////////////////////////////////////////////////////////////////////

总结特殊符号

.     任意一个字符

*   *号前面的字符0个或多个

.*  任意个任意字符

?  0或1个?前面的字符

+  1或多个+或前面的字符

《?+需要用egrep》

///////////////////////////////////////////////////////////////////////////////////

表示或者  包含root 或者nologin都可以匹配到

[root@wangshaojun ~]# egrep --color 'root|nologin' 1.txt
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

.....

表示并且   包含‘root’并且包含‘nologin’的

[root@wangshaojun ~]# grep --color 'root' 1.txt |grep --color 'nologin'

operator:x:11:0:operator:/root:/sbin/nologin

表示整体

[root@wangshaojun ~]# egrep --color '(rr)+' 1.txt   ///表示出现1次或多次rr 
syrrrrrrrrronc:x:5:0:sync:/sbin:/bin/sync
halt:x:7:rro0:halt:/sbin:/sbin/halt
gopher:x:1rrrro3:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FrrroTP User:/var/ftp:/sbin/nologin

.....

给整体指定一个范围

[root@wangshaojun ~]# egrep --color '(rr){1,3}' 1.txt
syrrrrrrrrronc:x:5:0:sync:/sbin:/bin/sync
halt:x:7:rro0:halt:/sbin:/sbin/halt
gopher:x:1rrrro3:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FrrroTP User:/var/ftp:/sbin/nologin

给整体指定一个倍数

[root@wangshaojun ~]# egrep --color '(rr){3}' 1.txt
syrrrrrrrrronc:x:5:0:sync:/sbin:/bin/sync

///////////////////////////////////////////////////////////////////////////////////

总结:? + () {} 需要用egrep       grep -E     grep\

shell入门-grep-3-egrep的更多相关文章

  1. shell入门-grep过滤-1

    正则表达式,就是一个字符串.有一定的规律.我们用指定的字符串匹配一个指定的行.指定的字符串就是正则表达式. 正则表达式有这几个工具:grep egrep sed awk 命令:gerep 说明:过滤出 ...

  2. shell编程系列8--文本处理三剑客之grep和egrep

    grep和egrep 第一种形式:grep [option] [pattern] [file1,file2...] 第二种形式:command | grep [option] [pattern] gr ...

  3. Linux正则表达式grep与egrep

    grep -io "http:/=[A-Z0-9]\{16\}" ./wsxf.txt >wsxf_urls.txt Linux正则表达式grep与egrep 正则表达式:它 ...

  4. Linux三剑客之grep 与 egrep

    grep: Linux上文本处理三剑客 grep:文本过滤(模式:pattern)工具; *(grep, egrep, fgrep) sed:stream editor,文本编辑工具: awk:Lin ...

  5. linux中grep和egrep的用法

    1. grep简介 grep (global search regular expression_r(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大 ...

  6. Linux shell入门基础(六)

    六.Shell脚本编程详解 将上述五部分的内容,串联起来,增加对Shell的了解 01.shell脚本 shell: # #perl #python #php #jsp 不同的脚本执行不同的文本,执行 ...

  7. grep与正则表达式,grep、egrep和fgrep

    grep用法详解:grep与正则表达式 首先要记住的是: 正则表达式与通配符不一样,它们表示的含义并不相同!正则表达式只是一种表示法,只要工具支持这种表示法, 那么该工具就可以处理正则表达式的字符串. ...

  8. Linux Shell 命令--grep

    从这篇开始,是文本内容操作,区别于文本操作. shell,perl,python,一直都是文本操作的专家语言,而我们今后学习的的将是shell的噱头--文本操作.下面提到最常见的一个: grep 这算 ...

  9. grep和egrep正则表达式

    Linux上文本处理三剑客 grep :文本过滤( 模式:pattern) 工具 grep, egrep, fgrep (不支持正则表达式搜索,但搜索纯文本的数据最快) sed :stream edi ...

  10. centos 正则,grep,egrep,流式编辑器 sed,awk -F 多个分隔符 通配符 特殊符号. * + ? 总结 问加星 cat -n nl 输出文件内容并加上行号 alias放~/.bash_profile 2015-4-10 第十三节课

    centos 正则,grep,egrep,流式编辑器 sed,awk -F 多个分隔符  通配符 特殊符号. * + ? 总结  问加星 cat -n  nl  输出文件内容并加上行号 alias放~ ...

随机推荐

  1. django 异步任务实现及Celery beat实现定时/轮询任务

    Celery定时任务 requirements celery==3.1.25 异步任务 django-celery==3.2.2 定时任务管理包 redis==2.10.6 django-redis- ...

  2. 【leetcode刷题笔记】Remove Duplicates from Sorted List II

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  3. Windows 2003 复制大文件提示系统资源不足的处理方法

    方案一: 修改虚拟内存,让虚拟内存的大小略微超过要复制的文件的大小. 方案二: 修改注册表,如下: 注册表设置1 单击开始,单击运行,在打开框中键入“REGEDIT“ ,然后单击“确定”. 找到并单击 ...

  4. java深入探究07-jsp

    RequestDispatcher是web资源包装类<jsp:include>只能实现固定jsp文件名他可以翻译为:RequestDispatcher(filename).include( ...

  5. QT 操作数据库SQLite实例

    #include "widget.h" #include <QApplication> #include <QtSql> #include <QTex ...

  6. Spark-Spark setMaster & WordCount Demo

    Spark setMaster源码 /** * The master URL to connect to, such as "local" to run locally with ...

  7. CentOS安装wireshark

    yum install wireshark-gnome yum install libpcap

  8. 列存储压缩技巧,除公共除数或者同时减去最小数,字符串压缩的话,直接去重后用数字ID压缩

    Column-store compression At a high level, doc values are essentially a serialized column-store. As w ...

  9. PHP 常量、PHP 变量全解析(超全局变量、变量的8种数据类型等)

    常量特点 常量一旦被定义就无法更改或撤销定义. 常量名不需要开头的$ 与变量不同,常量贯穿整个脚本是自动全局的. 作用域不影响对常量的访问 常量值只能是字符串或数字 设置 PHP 常量 如需设置常量, ...

  10. 百度编辑器UEditor配置toolbars工具条功能按钮

    两种方式: 1.代码中定义 <script id="container" name="content" type="text/plain&quo ...