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. Linux内核同步:RCU

    linux内核 RCU机制详解 简介 RCU(Read-Copy Update)是数据同步的一种方式,在当前的Linux内核中发挥着重要的作用.RCU主要针对的数据对象是链表,目的是提高遍历读取数据的 ...

  2. 还没被玩坏的robobrowser(4)——从页面上抓取感兴趣的内容

    背景 本节的知识实际上是属于Beautiful Soup的内容. robobrowser支持Beautiful Soup,一般来说通过下面3个方法获取页面上感兴趣的内容 find find_all s ...

  3. PNG怎么转换成32位的BMP保持透明

    32位BMP位图的格式是XRGB,就是X8位 R8位 G8位 B8位,当中的X8可以作为Alpha值用于透明, 只需要搜索一下PNG转32位BMP位图的软件就可以了,另外用PhotoShop下载插件打 ...

  4. 喜马拉雅FM接入

    最近有考虑接入,但是一方面由于沟通不畅等,另一方面没有浏览开发者协议,品牌规范等,多走了很多弯路,所以记下接入的注意事项和关键点 一. 接入前准备工作 喜马拉雅FM开放平台地址:http://open ...

  5. 永久代 PermGen 简述

    永久代(PermGen) 绝大部分 Java 程序员应该都见过 “java.lang.OutOfMemoryError: PermGen space “这个异常.这里的 “PermGen space” ...

  6. redis PUB/SUB(发布/订阅)

    PSUBSCRIBE订阅一个或多个符合给定模式的频道 PUBLISH将信息message 发送到指定的频道channel PUBSUB是一个查看订阅与发布系统状态的内省命令 PUBSUB CHANNE ...

  7. supervisor 完整安装步骤

    Supervisorhttp://www.jianshu.com/p/bf2b3f4dec73http://www.jianshu.com/p/9abffc905645http://blog.csdn ...

  8. Java数据结构和算法(四):栈

    一.简介 栈(英语:stack)又称为堆栈或堆叠,栈作为一种数据结构,是一种只能在一端进行插入和删除操作的特殊线性表.它按照先进后出的原则存储数据,先进入的数据被压入栈底(Bottom),最后的数据在 ...

  9. 【Unity】4.3 地形编辑器

    分类:Unity.C#.VS2015 创建日期:2016-04-10 一.简介 Unity拥有功能完善的地形编辑器,支持以笔刷绘制的方式实时雕刻出山脉.峡谷.平原.高地等地形.Unity地形编辑器同时 ...

  10. 使用tar命令解压的时候报错not in gzip format

    使用tar命令解压一个xx.tar.gz压缩包的时候报错not in gzip format,后用file xx.tar.gz查看一下格式发现是html document text格式的...