grep和rgrep和fgrep
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的更多相关文章
- grep与正则表达式,grep、egrep和fgrep
grep用法详解:grep与正则表达式 首先要记住的是: 正则表达式与通配符不一样,它们表示的含义并不相同!正则表达式只是一种表示法,只要工具支持这种表示法, 那么该工具就可以处理正则表达式的字符串. ...
- grep、egrep、fgrep的用法与特性详解
[转载自]http://tanxw.blog.51cto.com/4309543/1361993 开篇 学习Linux也有一段时间了,对Linux多少也算是有点了解了,越是了解也就越对这 ...
- grep、egrep、fgrep
grep: global search regular expression and printing
- grep egrep fgrep命令
一.grep.egrep.fgrep命令 本文中主要介绍了linux系统下grep egrep fgrep命令和正则表达式的基本参数和使用格式.方法.(注释:文中fg代表例子,) 1.1.基本定义: ...
- grep/pgrep/egrep/fgrep
Differences between grep, pgrep, egrep, and fgrep (Linux): grep grep is an acronym that stands for & ...
- grep, egrep, fgrep - 打印匹配给定模式的行
总览 SYNOPSIS grep [options] PATTERN [FILE...] grep [options] [-e PATTERN | -f FILE] [FILE...] 描述 DESC ...
- [转]grep 在文本中查找内容
转自: http://www.lampweb.org/linux/3/27.html 功能:grep系列是Linux中使用频率最高的文本查找命令.主要功能在一个或者多个文件中查找特定模式的字符串.如果 ...
- grep man 有删减 百科
NAME grep, egrep, fgrep, rgrep - print lines matching a pattern SYNOPSIS grep [OPTIONS] PATTERN [FIL ...
- [转] linux 查找文本过滤grep正则表达式命令详解用法
grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用 ...
随机推荐
- 来设置IE兼容模式
来设置IE兼容模式 文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本 ...
- 手把手教你ranorex_android源码instrument
话说ranorex能把android程序看的透彻,关键是在潜伏,他使用instrumentation,在每个界面(activity)里面,准确的说是onresume,也就是页面显示的时候,都给安装了个 ...
- 解决sklearn 随机森林数据不平衡的方法
Handle Imbalanced Classes In Random Forest Preliminaries # Load libraries from sklearn.ensemble im ...
- [转]greenplum(postgresql)之数据字典
greenplum是基于postgresql开发的分布式数据库,里面大部分的数据字典是一样的.我们在维护gp的时候对gp的数据字典比较熟悉,特此分享给大家.在这里不会详细介绍每个字典的内容,只会介绍常 ...
- nginx 443 https mark
#user nobody; worker_processes 4; #error_log logs/error.log; #error_log logs/error.log notice; ...
- office2010激活 错误代码0X8007000D,KMS激活0x8007000D错误解决办法,亲测成功激活
只针对VL版本 注意:此方法只对VL版本的,或者是MSDN版本通过替换文件转为VL版本的Office2010有效.零售版本的就别指望KMS激活了. 怎么看自己是不是VL版本的,只要看帮助里面激活的地方 ...
- Elasticsearch的基友Logstash(转)
Logstash 是一款强大的数据处理工具,它可以实现数据传输,格式处理,格式化输出,还有强大的插件功能,常用于日志处理. 一.原理 Input可以从文件中.存储中.数据库中抽取数据,Input有两种 ...
- robotframework + appium 获取android toast
android toast 获取主要方式是在出现toast的时候查找元素:xpath=//*[contains(@text,'记同步')] ,该xpath 表示为toast信息含有 "记 ...
- js中多个数字运算后值不对(失真)处理方法
最近遇到一个bug ,在js里面计算两个数字相减,633011.20-31296.30 得到的结果居然是601714.89,领导不乐意了说怎么少了0.01,我一听,噶卵达,来达鬼,不可能啊,我Goog ...
- JavaScript面向对象:类、方法、属性
JavaScript是一种基于对象的语言,与传统面向对象语言(C#.C++)相比,JavaScript中没有类的概念,其继承有两种基本形式:基于对象的继承和基于类型的继承(原型链继承).无论哪种形式的 ...