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. [高斯消元] POJ 2345 Central heating

    Central heating Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 614   Accepted: 286 Des ...

  2. HDU 3033 分组背包变形(每种至少一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. javascript类继承的一些实验

    其实一开始编js没怎么用过对象,一般都用func,func,func···但是用多了,感觉代码一点都不美观,还要这里包一个函数,那里包一个函数,或者一直都是函数调用,不好看,而且一些重用的都要重写的话 ...

  4. 用Pyinstaller打包发布exe应用 (转)经测可用

    安装Pyinstaller   1 按照习惯,我们使用pip来安装模块.我们一直以来强调,要用最偷懒的方法.写代码的人尤其如此.人生苦短,你要偷懒~   0Python | 如何用pip安装模块和包 ...

  5. 配置DelegatingFilterProxy使用Spring管理filter chain

    项目环境:JDK7 + Maven3.04 0. 项目使用springmvc作为controller层 1. 引入spring-security <dependency> <grou ...

  6. DataStructure——红黑树学习笔记

    1.前言 本文伪码和解释参考: http://blog.csdn.net/v_JULY_v/article/details/6105630 C实现的源码本文未贴出,请见: http://blog.cs ...

  7. android-webview开发中的各种使用方法(持续更,尽量全)

    最新坑A:(没看过的可以从下面开始处看起): 测试部门测出来一个坑,当多次点击退出后,会出现app崩溃现象,报如下错误: java.lang.IllegalArgumentException: Rec ...

  8. php 常用数组操作

    php常用的数组操作函数,包括数组的赋值.拆分.合并.计算.添加.删除.查询.判断.排序等 array_combine 功能:用一个数组的值作为新数组的键名,另一个数组的值作为新数组的值 <?p ...

  9. java开发环境搭建

    回顾环境安装的流程. 安装jdk 配置java开发环境 配置path以及classpath. 我是在http://www.oracle.com/上下载的.点击Downloads-->java f ...

  10. 事件问题 Event

    Event事件可以理解为在异步过程中实现同步的操作.但是要注意不要过分的使用Event,否则异步就失去了意义. 直接通过代码来说明: #include