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. 【转】我的第一次和最后一次 Hackathon 经历

    我的第一次和最后一次 Hackathon 经历 在旧金山地区经常有一些叫做“Hackathon”的活动,吸引挺多人参加.我一直听说这个名字,可是一直不知道它到底是什么.我从来对竞赛式的活动不感兴趣,我 ...

  2. 如何查看java进程

    一.Linux篇方法一 ps -ef|grep java 方法二 jps -l (显示java进程的Id和软件名称) jps -lmv(显示java进程的Id和软件名称:显示启动main输入参数:虚拟 ...

  3. LICEcap 录制Gif动画

    使用 能录制Gif动画

  4. JavaScript语言精粹之对象

    用object.hasOwnProperty(variable)来确定这个属性名是否为该对象成员,还是来自于原型链. for(my in obj){ if(obj.hasOwnProperty(my) ...

  5. java类中serialversionuid 作用 是什么?举个例子说明(转)

    serialVersionUID适用于Java的序列化机制.简单来说,Java的序列化机制是通过判断类的serialVersionUID来验证版本一致性的.在进行反序列化时,JVM会把传来的字节流中的 ...

  6. Hbase/Hadoop Java API编程常用语句

    从scanner获取rowkey: for(Result rr : scanner){ String key =Bytes.toString(rr.getRow())} HBase API - Res ...

  7. MySQL8的新特性CTE

    [瞎BB] 十一长假的最后一天,想到明天要就回去上班了:内心的激动无法用平常的言语来表达,可能是国人的感情向来比较内敛(这个锅不能我一个人背) 也可能是我们比较重行动(Just Do IT).但... ...

  8. python3 元类编程的一个例子

    [引子] 虽然我们可以通过“class”语句来定义“类”,但是要想更加细粒度的控制“类”的创建,要使用元类编程才能实现. 比如说我们要实现这样的一个约束.所有项目中用到的类都应该要为它定义的方法提供文 ...

  9. java的跳转和重定向,加载显示层

    HttpServltRequest  req,   HttpDervletResponse resp 的 req.sendRedirect('页面');跳转到页面  浏览器地址跳转 --------- ...

  10. [CTCI] 子串判断

    子串判断 题目描述 现有一个小写英文字母组成的字符串s和一个包含较短小写英文字符串的数组p,请设计一个高效算法,对于p中的每一个较短字符串,判断其是否为s的子串. 给定一个string数组p和它的大小 ...