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. 数据表格datagrid内容整理

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  2. Git-rebase 小笔记

    转自: https://blog.yorkxin.org/posts/2011/07/29/git-rebase/ 最近刚好有个机会整理很乱的Git commit tree,终于搞懂了rebase 的 ...

  3. ruby 编译安装,gem国内源ruby.taobao.org

    centos6.6final 一.安装依赖包(使用默认CENTOS更新源): # yum install openssl* openssl-devel zlib-devel gcc gcc-c++ m ...

  4. C++重载流运算符,将存储结构体的vector直接写入文件

    我们知道,当vector很大的时候,如果使用循环的方式将其中的元素写入文件将非常费时,因此有没有办法将vector一次性写入文件呢? 采用流运算符重载的方法可以做到,不仅基本类型的vector可以一次 ...

  5. python2.7安装matplotlib遇到的问题及解决方法

    python2.7下import matplotlib报错 第一个报错是:缺少这个pyparsing-2.1.4.win32-py2.7.exe 直接下载安装就行 第二个报错是:缺少cycler 这个 ...

  6. greendao 3.1.0在android studio中配置

    1 项目根build.gradle classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0' 2 app中build.gradle apply p ...

  7. Dapper学习笔记(3)-增、删、改、查

    一.建表 在数据库中建立如下三张表: CREATE TABLE [dbo].[T_User] ( , ) PRIMARY KEY NOT NULL, ) NOT NULL, ) NULL, ) NUL ...

  8. iOS中AutoLayer自动布局流程及相关方法

    关于UIView的Layer,IOS提供了三个方法: 1.layoutSubviews 在iOS5.1和之前的版本,此方法的缺省实现不会做任何事情(实现为空),iOS5.1之后(iOS6开始)的版本, ...

  9. Mac下手动安装SafariDriver extension

    环境:Mac OS X Yosemite 10.10.4下, Safari 8 Step 1:第一次运行SafariDriver时,先找到WebDriver extension的安装路径,比如/Use ...

  10. 遗传算法的C语言实现(一):以非线性函数求极值为例

    以前搞数学建模的时候,研究过(其实也不算是研究,只是大概了解)一些人工智能算法,比如前面已经说过的粒子群算法(PSO),还有著名的遗传算法(GA),模拟退火算法(SA),蚁群算法(ACA)等.当时懂得 ...