查找特定字符串并颜色显示

[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使用方法具体解释的更多相关文章

  1. 12个 Linux 中 grep 命令的超级用法实例

    12个 Linux 中 grep 命令的超级用法实例 你是否遇到过需要在文件中查找一个特定的字符串或者样式,但是不知道从哪儿开始?那么,就请grep来帮你吧. grep是每个Linux发行版都预装的一 ...

  2. linux中grep命令的使用

    转载:http://blog.csdn.net/universsky/article/details/8866402 linux中grep命令的使用 grep (global search regul ...

  3. Linux中Grep常用的15个例子【转】

    转自:https://www.aliyun.com/jiaocheng/1390860.html?spm=5176.100033.1.9.6a1e41e8Pdjynm 摘要:Grep命令主要用于从文件 ...

  4. traceroute在linux中的使用方法

    traceroute在linux中的使用方法 一.traceroute的实现原理 二.traceroute命令使用方法 1.命令格式 2.常用命令参数 3.使用实例 一.traceroute的实现原理 ...

  5. Linux中grep和egrep命令详解

    rep / egrep 语法: grep  [-cinvABC]  'word'  filename -c :打印符合要求的行数-i :忽略大小写-n :在输出符合要求的行的同时连同行号一起输出-v ...

  6. linux中grep工具

    正则表达式 以前我们用grep在一个文件中找出包含某些字符串的行,比如在头文件中找出一个宏定义.其实grep还可以找出符合某个模式(Pattern)的一类字符串.例如找出所有符合xxxxx@xxxx. ...

  7. linux中grep命令的用法

    作为linux中最为常用的三大文本(awk,sed,grep)处理工具之一,掌握好其用法是很有必要的. 首先谈一下grep命令的常用格式为:[grep  [选项]  "模式"  [ ...

  8. linux中grep/egrep的使用

    grep也是linux中查找的一个利器,运维.程序员必掌握的 下面针对grep的参数进行说明: --color  重点标记匹配到项grep "a word" datafile -- ...

  9. Linux中grep命令的12个实践例子

    grep是每个Linux发行版都预装的一个强有力的文件模式搜索工具.无论何种原因,如果你的系统没有预装它的话,你可以很容易的通过系统的包管理器来安装它(Debian/Ubuntu系中的apt-get和 ...

随机推荐

  1. oracle常见错误类型

    http://www.cnblogs.com/whyhappy/p/6232258.html

  2. structs 拦截器

    首先,要跟大家道个歉,前一阵子为给客户个一个DEMO,忙得不可开交,所以很久没有更新Blog.提到这个DEMO我想顺便跟大家分享一下心得——如果大家希望快速开发,一个类似Struts 2这样的简单方便 ...

  3. 百度Echarts使用心得

    echarts官网:http://echarts.baidu.com/index.html 最近用了echart,有一下问题需要注意: 1.echarts的使用实例 代码:从地图中取得whitejso ...

  4. phantomjs API

    phantomjs使用说明         phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...

  5. JSP基础之 C标签中的 varStatues属性

    变量状态参数,该属性有5个常用值count 表示当前遍历集合的元素个数index 表示当前遍历到集合的第几个元素current 表示当前的集合元素first 表示集合的第一个元素last 表示集合的最 ...

  6. python版去UTF-8 BOM

    今天给app弄银联支付接口.直接copy银联的sdk.结果.安卓和ios始终报json格式错误.找了半天.都没找到问题.最后怀疑可能是BOM破坏了json的数据格式转换.验证后确认是BOM的问题.为方 ...

  7. AngularJS心得体会

    AngularJS早些时候有过了解,知道这是一个JS的MVC框架,同类型的框架还有Backbone等.这次是由于项目需要,学习了两天的Angular后开始着手改之前的项目代码,这里大概说一下这一周学习 ...

  8. xml文件的解析

    1. xml文件的解析 void CDataMgr::readStringData() { std::string xml_name = "config/string.xml"; ...

  9. python核心编程-第四章-习题

    1.身份.类型.值.其中,身份是每个对象的标识,与内存地址密切相关,可用id()返回:类型决定了对象可以保存什么类型的值,用type()函数.isinstance()函数可以得到对象的类型:值就是对象 ...

  10. Ubuntu 14.04卸载安装失败的Mysql数据库,以及重新安装配置

    一.删除原来Mysql 1.删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 2.删除mqsql的配置文件 sudo rm /etc/mysql/ -R 3.自动卸载my ...