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,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用 ...
随机推荐
- ural 1091. Tmutarakan Exams(容斥)
http://acm.timus.ru/problem.aspx? space=1&num=1091 从1~s中选出k个数,使得k个数的最大公约数大于1,问这种取法有多少种. (2<=k ...
- SharePoint利用HttpModule的Init方法实现全局初始化
接上篇 我们知道,HttpRuntime中会对每一个Request创建一个HttpApplication对象(HttpApplicationFactory从一个HttpApplication池来拿). ...
- MySQL 5.7.19 CentOS 7 安装
Linux的版本有很多,因此下载mysql时,需要注意下载对应Linux版本的MySql数据库文件.以下方法也适合centOS 7 的mysql 5.7.* 版本的安装.安装方法我整理为16步. 1: ...
- Java – Check if Array contains a certain value?
Java – Check if Array contains a certain value?1. String Arrays1.1 Check if a String Array contains ...
- spring中InitializingBean接口使用理解(转)
InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法. 测试程序如下: imp ...
- Windows 计划任务 Task Schedule 怎么 运行 .bat文件
1. 新建 test.bat 需要切换文件夹以后 并且执行程序. cd /D "F:\xxxfolder" && dotnet testdll.dll 2. 直接设 ...
- php分享十八七:mysql基础
mysql操作数据库代码: $link = @mysql_connect('localhost:3306', 'root', 'root') or die(mysql_error()); mysql_ ...
- 如何使用好android的可访问性服务(Accessibility Services)
原文:http://android.eoe.cn/topic/android_sdk * 主题* Manifest声明和权限 可访问性服务声明 可访问性服务配置 AccessibilityServic ...
- golang bufio、ioutil读文件的速度比较(性能测试)和影响因素分析
前言 golang读取文件的方式主要有4种: 使用File自带的Read方法 使用bufio库的Read方法 使用io/ioutil库的ReadAll() 使用io/ioutil库的ReadFile( ...
- C/C++中的volatile关键字
volatile提醒编译器它后面所定义的变量随时都有可能改变,因此编译后的程序每次需要存储或读取这个变量的时候,都会直接从变量地址中读取数据. 如果没有volatile关键字,则编译器可能优化读取和存 ...