linux中grep使用方法具体解释
查找特定字符串并颜色显示
[root@fwq test]# grep -n 'the' regular_express.txt --color=auto
8:I can't finish the test.
12:the symbol '*' is represented as start.
15:You are the best is mean you are the no. 1.
16:The world <Happy> is the same with "glad".
18:google is the best tools for search keyword.
反向选择查找特定字符串并颜色显示
[root@fwq test]# grep -vn 'the' regular_express.txt --color=auto
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
......
忽略大写和小写查找特定的字符
[root@fwq test]# grep -in 'the' regular_express.txt
使用 [] 来查找集合字符:
[root@fwq test]# grep -n 't[ae]st' regular_express.txt
8:I can't finish the test.
9:Oh! The soup taste good.
查找有‘oo’字符串
[root@fwq test]# grep -n 'oo' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
查找有‘oo’字符串,可是不要前面有g的,即剔除goo
[root@fwq test]# grep -n '[^g]oo' regular_express.txt
2:apple is my favorite food.
3:Football game is not use feet only.
18:google is the best tools for search keyword.
19:goooooogle yes!
查找非小写字母加oo的内容
[root@fwq test]# grep -n '[^a-z]oo' regular_express.txt
3:Football game is not use feet only.
获取有数字的一行
[root@fwq test]# grep -n '[0-9]' regular_express.txt
5:However, this dress is about $ 3183 dollars.
15:You are the best is mean you are the no. 1.
[root@fwq test]# grep -n '[^[:lower:]]oo' regular_express.txt
3:Football game is not use feet only.
查询以the开头的字符
[root@fwq test]# grep -n '^the' regular_express.txt
12:the symbol '*' is represented as start.
查询开头是小写字母的内容
[root@fwq test]# grep -n '^[a-z]' regular_express.txt
2:apple is my favorite food.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.
12:the symbol '*' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
查询第一个字符不是大写的
[root@fwq test]# grep -n '^[[:lower:]]' regular_express.txt
2:apple is my favorite food.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.
12:the symbol '*' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
查询不是以英文开头的字符
[root@fwq test]# grep -n '^[^a-zA-Z]' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
21:# I am VBird
查询结尾是小数点的行的内容.
[root@fwq test]# grep -n '\.$' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.
11:This window is clear.
12:the symbol '*' is represented as start.
15:You are the best is mean you are the no. 1.
16:The world <Happy> is the same with "glad".
17:I like dog.
18:google is the best tools for search keyword.
20:go! go! Let's go.
查找“空白行”
[root@fwq test]# grep -n '^$' regular_express.txt
22:
通配符.和*的使用,.(小数点)代表一定有一个随意字符,*代表反复前一个到无穷多次的意思
[root@fwq test]# grep -n 'g..d' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
16:The world <Happy> is the same with "glad".
查询出现随意数字的行列
[root@fwq test]# grep -n '[0-9][0-9]*' regular_express.txt
5:However, this dress is about $ 3183 dollars.
15:You are the best is mean you are the no. 1.
查询出现两个o的字符串
[root@fwq test]# grep -n 'o\{2\}' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
查询出现2-5个o的字符串,后面在接一个g的字符串
[root@fwq test]# grep -n 'o\{2,5\}g' regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!
查询出现2个以上o的字符串,后面在接一个g的字符串
[root@fwq test]# grep -n 'o\{2,\}g' regular_express.txt
18:google is the best tools for search keyword.
19:goooooogle yes!
linux中grep使用方法具体解释的更多相关文章
- 12个 Linux 中 grep 命令的超级用法实例
12个 Linux 中 grep 命令的超级用法实例 你是否遇到过需要在文件中查找一个特定的字符串或者样式,但是不知道从哪儿开始?那么,就请grep来帮你吧. grep是每个Linux发行版都预装的一 ...
- linux中grep命令的使用
转载:http://blog.csdn.net/universsky/article/details/8866402 linux中grep命令的使用 grep (global search regul ...
- Linux中Grep常用的15个例子【转】
转自:https://www.aliyun.com/jiaocheng/1390860.html?spm=5176.100033.1.9.6a1e41e8Pdjynm 摘要:Grep命令主要用于从文件 ...
- traceroute在linux中的使用方法
traceroute在linux中的使用方法 一.traceroute的实现原理 二.traceroute命令使用方法 1.命令格式 2.常用命令参数 3.使用实例 一.traceroute的实现原理 ...
- Linux中grep和egrep命令详解
rep / egrep 语法: grep [-cinvABC] 'word' filename -c :打印符合要求的行数-i :忽略大小写-n :在输出符合要求的行的同时连同行号一起输出-v ...
- linux中grep工具
正则表达式 以前我们用grep在一个文件中找出包含某些字符串的行,比如在头文件中找出一个宏定义.其实grep还可以找出符合某个模式(Pattern)的一类字符串.例如找出所有符合xxxxx@xxxx. ...
- linux中grep命令的用法
作为linux中最为常用的三大文本(awk,sed,grep)处理工具之一,掌握好其用法是很有必要的. 首先谈一下grep命令的常用格式为:[grep [选项] "模式" [ ...
- linux中grep/egrep的使用
grep也是linux中查找的一个利器,运维.程序员必掌握的 下面针对grep的参数进行说明: --color 重点标记匹配到项grep "a word" datafile -- ...
- Linux中grep命令的12个实践例子
grep是每个Linux发行版都预装的一个强有力的文件模式搜索工具.无论何种原因,如果你的系统没有预装它的话,你可以很容易的通过系统的包管理器来安装它(Debian/Ubuntu系中的apt-get和 ...
随机推荐
- 异常:ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed...
ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed: com.movie.类 放到lib 包下 \W ...
- Restful风格的springMVC配搭ajax请求的小例子
1. GET请求的例子 ajax代码: 请求参数拼接在url后面(参数在服务器可通过HttpServletRequest获取,也可以直接通过@RequestParam自动注入,参考DELETE例子的方 ...
- 1. 用U盘安装Centos6.5 + Win7 双系统
一. 用U盘安装Centos6.5 + Win7 双系统 准备工作:U盘(8G).需要安装的Centos6.5系统(64bit).EasyBCD(用来修复引导,否则开机只有一个系统). ...
- stagefright框架(一)Video Playback的流程
在Android上,預設的多媒體框架(multimedia framework)是OpenCORE. OpenCORE的優點是兼顧了跨平台的移植性,而且已經過多方驗證,所以相對來說較為穩定:但是其缺點 ...
- Respond.js让IE6-8支持CSS3 Media Query
原文地址:http://caibaojian.com/respondjs.html 使用方式 官方demo地址:http://scottjehl.github.com/Respond/test ...
- Android服务之AIDL
在android开发过程中,为了让其他的应用程序,也可以访问本应用程序的服务,android系统采用远程过程调用来实现.android通过接口来公开定义的服务.我们将能够夸进程访问的服务成为AIDL服 ...
- (Oracle EBS)和标准用户有关的处理的API [Z]
/* 和标准用户有关的处理的API. */ ---和用户处理有关的API FND_USER_PKG ---和用户密码处理有关的API fnd_web_sec ---和用户职责处理有关的API FND_ ...
- HDU 5728 - PowMod
HDU 5728 - PowMod 题意: 定义: k = ∑(i=1,m) φ(i∗n) mod 1000000007 给出: n,m,p ,且 n 无平方因子 求: ans= k^(k^(k ...
- Mongodb 安装和启动
一.首先去官网下载对应的的mongodb ,本人的操作系统是win7 64位 mongodb-win32-x86_64-2.0.6.rar 解压安装:进入到bin目录下,会看到N多的.exe文件 二. ...
- python中的星号*、**的意义
我们都知道,定义一个函数,当传入的参数个数未知时就可以使用*来表示. 单引号*: def test(*args): if len(args) >= 4: print(arg[3]) test(1 ...