grep (缩写来自Globally search a Regular Expression and Print)

是一种强大的文本搜 索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。Unix的grep家族包括

grep、egrep和fgrep

案例1:精确的匹配

[root@localhost ~]# cat 1.txt | grep

all all tooall to

alltoall all allto100

uuualltoall

[root@localhost ~]# cat 1.txt | grep -w "all"

all tooall to

alltoall all

案例2:加入自动颜色

[root@localhost ~]# cat 1.txt | grep -w "all" --color=auto

all tooall

to alltoall all

案例3 :取反参数 -v 选项
[root@localhost ~]# ps -ef | grep ssh

root       2055      1  0 09:03 ?        00:00:00 /usr/sbin/sshd

root      24498   2055  0 11:21 ?        00:00:01 sshd: root@pts/0

root      24657  24502  0 12:11 pts/0    00:00:00 grep ssh

[root@localhost ~]# ps -ef | grep ssh | grep -v grep

root       2055      1  0 09:03 ?        00:00:00 /usr/sbin/sshd

root      24498   2055  0 11:21 ?        00:00:01 sshd: root@pts/0

[root@localhost ~]

案例4 :统计出现的次数
[root@localhost ~]# grep -c "all" 1.txt

4

[root@localhost ~]#

案例5:显示匹配的行数

[root@localhost ~]# grep -n "all"

1.txt 1:all tooall

2:to alltoall all

3:allto100

4:uuualltoall

案例6:显示匹配的文件

[root@localhost ~]# grep "all" 1.txt 2.txt 4.txt

1.txt:all tooall

1.txt:to alltoall all

1.txt:allto100

1.txt:uuualltoall

2.txt:alltohell

2.txt

4.txt:allheot4.txt

[root@localhost ~]# grep -l "all" 1.txt 2.txt 4.txt

1.txt

2.txt

4.txt

案例7:忽略字符大小写
[root@localhost ~]# cat 1.txt | grep -i "ALL"

all tooall

ALAALLL

to alltoall all

allto100

uuualltoall

linux grep的更多相关文章

  1. linux grep命令

    linux grep命令1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressio ...

  2. linux grep命令详解

    linux grep命令详解 简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 ...

  3. 如何使用Unix/Linux grep命令——磨刀不误砍柴工系列

     http://man.linuxde.net/grep ---------------------------------------------------- 如何使用Unix/Linux gre ...

  4. linux grep命令总结

    风生水起善战者,求之于势,不责于人,故能择人而任势. 博客园    首页    新随笔    联系    订阅    管理 posts - 791,  comments - 394,  trackba ...

  5. linux grep 从入门到精通

    linux grep 从入门到精通 一.初级 搜索日志 grep "186" catalina.out 在新输出日志中监听固定字符串 tail -f catalina.out | ...

  6. Linux grep命令详解[备份]

    linux grep命令 1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressi ...

  7. linux grep命令(linux在文件中搜索内容)

    转自:https://www.cnblogs.com/end/archive/2012/02/21/2360965.html linux grep命令 1.作用Linux系统中grep命令是一种强大的 ...

  8. linux grep 搜索查找

    查找关键字在哪些文件夹中的哪些文件中出现(只列出文件名称): grep -l 15386257298 */* 查找关键字在哪些文件夹中的哪些文件中出现(列出文件名称+关键字): grep -o 153 ...

  9. linux grep 查询多行的方法

    linux grep 查询多行的方法 经常查询 git log 中使用的方法, 如下 git log |grep "xxxx" 如果想查询多行的话, 就有些尴尬, 如果想查询多行的 ...

  10. linux grep的用法

    linux grep的用法<pre>[root@iZ23uewresmZ ~]# cat /home/ceshis.txtb124230 b034325 a081016 m7187998 ...

随机推荐

  1. Linux版Matlab R2015b的bug——脚本运行的陷阱(未解决)

    0 系统+软件版本 系统:CentOS 6.7 x64, 内核 2.6.32-573.el6.x86_64软件:Matlab R2015b(包括威锋网和东北大学ipv6下载的资源,都测试过) 1 脚本 ...

  2. QT 做软件盘

    最近搞了一个组织细胞脱水机项目,当然,对于国内的项目都是仿来仿去的,我们也不例外,开启被仿机器后,第一个看到的界面就是用户登录界面,需要输入中文,作为一个程序员,我的第一反应就是我需要采用什么用的框架 ...

  3. IIS7 WebAPI 404.0 Error

    <system.webServer><modules runAllManagedModulesForAllRequests="true"/></sys ...

  4. NSOperation的start与main,并发与非并发。

    http://blog.csdn.net/a2331046/article/details/52294006 在ios4以前,只有非并发的情况下,队列会为operation开启一个线程来执行.如果是并 ...

  5. 《JavaScript高级程序设计》读书笔记--前言

    起因 web编程过程使用javascript时感觉很吃力,效率很低.根本原因在于对javascript整个知识体系不熟,看来需要找些书脑补一下,同时欢迎众网友监督. 大神推荐书籍 看了博客大神们推荐的 ...

  6. JavaScript 变量作用域

    一. 变量声明 变量用var关键字来声明,如下所示: 变量在未声明的情况下被初始化,会被添加到全局环境. JavaScript执行代码时,会创建一个上下文执行环境,全局环境是最外围的环境.每个函数在被 ...

  7. linux环境下安装tomcat并配置tomcat日志分割

    1.直接解压apache-tomcat-7.0.69.tar.gz 存放在/home目录下 根据需要自定义tomcat名称 mv apache-tomcat-7.0.69 Tomcat7 2.解压cr ...

  8. DataList无数据如何显示

    <FooterTemplate> <asp:Label runat="server" ID="emptyLb" Text="No D ...

  9. java中的foreach循环

    foreach语句是java5的新特征之一,在遍历数组.集合方面,foreach为开发人员提供了极大的方便. foreach语句是for语句的特殊简化版本,但是foreach语句并不能完全取代for语 ...

  10. JavaScript Cookies

    JavaScript Cookies 当 web 服务器向浏览器发送 web 页面时,在连接关闭后,服务端不会记录用户的信息.Cookies 的作用就是用于存储 web 页面的用户信息. Cookie ...