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和 ...
随机推荐
- pktgen使用详细教程
网上有很多讲解pktgen的文章,但总是不够全面细致,看完之后自己还是不会写pktgen测试脚本,为此本文对pktgen进行详细的阐述,让大家看完本文后能够自己动手写pktgen shell. 1.p ...
- POJ1094 Sorting It All Out(拓扑排序)
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30110 Accepted: 10 ...
- UGUI Button控件
今天一起来学习下Button控件, Button控件其实是由Text,Button,Image组件形成的. 这里就简单介绍下Button组件 Interactable: 代表该组件是否进行交互, 我们 ...
- 键盘code码速查表
键盘 Key Code对照表 字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C ...
- Xshell同时向多个会话发送指令的方法
我们平时使用XSHELL.SecureCRT.putty等ssh连接工具连接到远程主机,每次输入指令都是在单一会话窗口,如果有很多台会话,需要同时输入同样的指令,我们就不用一一输入,浪费时间和精力.可 ...
- 开始我的.NET的学习旅程
今天开始了我的.NET学习之旅,终于弄懂了.NET与C#的关系,一开始还以为它们就是一个东西,原来不是那样的,C#只是基于.NET平台环境下运行的一种语言,.NET不止可以运行C#语言,更可以运行其他 ...
- css3动画学习的例子来源
1.这里面有不同的鼠标经过图片效果,图片变大变小,出现文字,向左移动等等 http://dinolatoga.com/demo/webkit-image-hover-effects/ 2.有一篇博客, ...
- Git GUI简易使用教程
Git GUI简易使用教程:先上图~~~~~ 一. 先从添加文件开始讲(先上图): 1.选中要添加的文件,点击菜单栏的“提交”,选中“缓存为提交”,
- 计算两个集合的交集数字(java)
循环判断2个数组 将相同的公共元素复制到新数组中即可 import java.util.Arrays; public class count_same_number { public static i ...
- Visual Studio 使用技巧
整理备用: 1. 键入prop后,连续按两下tab, 可以自动生成属性,然后输入类型和名称. 类似的还有: propg, 生成private set的属性 propfull,生成私有字段,和相应属性 ...