Linux环境下。

(1)grep对标签元字符的表示。

[berry@berry:practice] grep 'w\(es\).*\1' text
northwest NW Charles Main 3.0 .98 3 34
[berry@berry:practice] grep -E 'w\(es\).*\1' text
grep: Invalid back reference
[berry@berry:practice] grep -E 'w(es).*\1' text
northwest NW Charles Main 3.0 .98 3 34
[berry@berry:practice] egrep 'w(es).*\1' text
northwest NW Charles Main 3.0 .98 3 34

(2)grep对锚定单词的元字符的表示。

[berry@berry:practice] grep '\<no\>' text
no one
no no123
[berry@berry:practice] grep -E '\<no\>' text
no one
no no123
[berry@berry:practice] egrep '\<no\>' text
no one
no no123

(3)对重复作用的元字符的表示。

[berry@berry:practice] grep '\.[0-9]\{2\}[^0-9]' text
northwest NW Charles Main 3.0 .98 3 34
northwest NW Charles Main 3.0 .98 3 34
[berry@berry:practice] grep -E '\.[0-9]{2}[^0-9]' text
northwest NW Charles Main 3.0 .98 3 34
northwest NW Charles Main 3.0 .98 3 34
[berry@berry:practice] egrep '\.[0-9]{2}[^0-9]' text
northwest NW Charles Main 3.0 .98 3 34
northwest NW Charles Main 3.0 .98 3 34

(4)Unix环境下,(Solaris egrep)

# egrep ‘\.[0-9]{2}[^0-9]' datafile
<no output; not recognized with or without backslashes>

说明
1 扩展元字符{}用来表示重复。除非在前面加上反斜杠,否则Gnu 和UNIX 版本的正规grep 无法
识别这个扩展元字符。该正则表达式的意思是:搜索这样的行,该行包含这样的字符串,第一个
字符是一个点号\.,紧跟着一个0~9之间的数字[0-9],如果该字符串重复两次\{2\},则后面就是
一个非数字的字符[^0-9]。
2 若使用扩展grep或者grep -E选项,则在表示重复的元字符{2}的括号前面就不需要加反斜杠了。
3 因为Gnu 版本的egrep 跟grep -E的功能一样,因此这个例子的结果跟前面相同。
4 这是标准的UNIX下的egrep,不论是否有反斜杠它都无法识别花括号元字符{}。

(5)rgrep的使用,跟其他grep家族成员不同,rgrep 可以递归访问目录树。rgrep 有一些命令行选项支持跟
标准的grep 一样的选项。

[berry@berry:practice] grep "hello" text
adfdfdfdfddhellodffdf
adfdfdfdfddhellodffdf
adfdfdfdfddhellodffdf
adfdfdfdfddhellodffdf
adfdfdfdfddhellodffdf
hello word
hello word
hello berry!Good morning,every one!
hello berry!Good morning,every one!
hello berry!Good morning,every one!
hello word
hello berry!Good morning,every one!
hello berry!Good morning,every one!
hello word
hello berry!Good morning,every one!
hello word
hello berry!Good morning,every one!
[berry@berry:practice] rgrep "hello" .
./b.txt:A hello world
./text:adfdfdfdfddhellodffdf
./text:adfdfdfdfddhellodffdf
./text:adfdfdfdfddhellodffdf
./text:adfdfdfdfddhellodffdf
./text:adfdfdfdfddhellodffdf
./text:hello word
./text:hello word
./text:hello berry!Good morning,every one!
./text:hello berry!Good morning,every one!
./text:hello berry!Good morning,every one!
./text:hello word
./text:hello berry!Good morning,every one!
./text:hello berry!Good morning,every one!
./text:hello word
./text:hello berry!Good morning,every one!
./text:hello word
./text:hello berry!Good morning,every one!
./dir1/a.txt:hello

(6)fgrep 的命令行形式跟grep 相似,但是它不识别任何正则表达式元字符。所有的字符都
表示它们自己。一个插入符号就表示插入符号,一个美元符号就表示美元符号等等。-F 选项
使得Gnu grep 精确地模仿fgrep。

[berry@berry:practice] fgrep '[A-Z]****[0-9]..$5.00' text
[A-Z]****[0-9]..$5.00
[berry@berry:practice] grep -F '[A-Z]****[0-9]..$5.00' text
[A-Z]****[0-9]..$5.00

(7)grep -w no text 和grep '\<no\>' text的效果是一样的,都是表示按照单词方式匹配,而不是只是作为

单词的一部分进行匹配。

[berry@berry:practice] grep '\<no\>' text
no one
no one
no no123
[berry@berry:practice] grep 'no' text
no one
no one
no no123
northwest NW Charles Main 3.0 .98 3 34
northwest NW Charles Main 3.0 .98 3 34
noone
[berry@berry:practice] grep -w "no" text
no one
no one
no no123

grep和rgrep和fgrep的更多相关文章

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

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

  2. grep、egrep、fgrep的用法与特性详解

    [转载自]http://tanxw.blog.51cto.com/4309543/1361993 开篇        学习Linux也有一段时间了,对Linux多少也算是有点了解了,越是了解也就越对这 ...

  3. grep、egrep、fgrep

    grep: global search regular expression and printing

  4. grep egrep fgrep命令

    一.grep.egrep.fgrep命令 本文中主要介绍了linux系统下grep egrep fgrep命令和正则表达式的基本参数和使用格式.方法.(注释:文中fg代表例子,) 1.1.基本定义: ...

  5. grep/pgrep/egrep/fgrep

    Differences between grep, pgrep, egrep, and fgrep (Linux): grep grep is an acronym that stands for & ...

  6. grep, egrep, fgrep - 打印匹配给定模式的行

    总览 SYNOPSIS grep [options] PATTERN [FILE...] grep [options] [-e PATTERN | -f FILE] [FILE...] 描述 DESC ...

  7. [转]grep 在文本中查找内容

    转自: http://www.lampweb.org/linux/3/27.html 功能:grep系列是Linux中使用频率最高的文本查找命令.主要功能在一个或者多个文件中查找特定模式的字符串.如果 ...

  8. grep man 有删减 百科

    NAME grep, egrep, fgrep, rgrep - print lines matching a pattern SYNOPSIS grep [OPTIONS] PATTERN [FIL ...

  9. [转] linux 查找文本过滤grep正则表达式命令详解用法

    grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用 ...

随机推荐

  1. Java设计模式(八)----代理模式

    代理模式 1.生活中: 代理就是一个人或者一个组织代表其它人去做一件事的现实生活中的. 在一些情况下,一个客户不想或者不能够直接引用一个对象,而代理对象能够在client和目标对象之间起到中介的作用. ...

  2. 手把手教你ranorex_android源码instrument

    话说ranorex能把android程序看的透彻,关键是在潜伏,他使用instrumentation,在每个界面(activity)里面,准确的说是onresume,也就是页面显示的时候,都给安装了个 ...

  3. php分享三十一:编程中的一些特殊写法

    1:for for ( ; $i < $accept_l ; $i++ ) for($i = 0, $num = count($array); $i < $num; $i++) for ( ...

  4. [sql]mysql指引(整理中...)-对db的分类

    参考 db存储及分层 一个db一个文件夹. 一张表两个文件frm是存表结构的,ibd是存数据的 连接层: sock ip sql层: 存储层: 2018年4月1日 20:53:54小结: 时间太久,抓 ...

  5. Django使用manage.py备份与恢复数据

    Django dumpdata and loaddata django database model dumpdata dumpdata command It is a django manageme ...

  6. NGINX宏观手记(变量|配置)

    前言 任何一个工具都有它的灵魂所在,作为一个PHP程序员,我们可能仅仅使用了它的一小部分,这篇文章让你更加了解Nginx,本章大多都是总结.翻译.整理 ,希望你可以知道nginx不仅仅是PHP的附属品 ...

  7. 破解AI大脑黑盒迈出新一步!谷歌现在更懂机器,还开源了研究工具

    https://zhuanlan.zhihu.com/p/34306323 https://distill.pub/2018/building-blocks/

  8. 把虚拟教练带回家,「EuMotus」想用AI实现高精度运动反馈系统

    https://36kr.com/p/5089139.html 无需穿戴设备,只需一个红外摄像头和+已安装好EuMotus专利软件的手提电脑 由政府主导的高达2200亿美金的健身与运动支出,15%的健 ...

  9. Android 编程下将 Bitmap 转为 InputStream

    某些情况下会用到这种非主流的转换方式,最近项目中用到,记录下. ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compres ...

  10. 【Spring】Spring Session的简单搭建与源码阅读

    搭建一个简单的Spring Session例子 引入依赖包 <dependencies> <dependency> <groupId>org.springframe ...