linux grep
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的更多相关文章
- linux grep命令
linux grep命令1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressio ...
- linux grep命令详解
linux grep命令详解 简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 ...
- 如何使用Unix/Linux grep命令——磨刀不误砍柴工系列
http://man.linuxde.net/grep ---------------------------------------------------- 如何使用Unix/Linux gre ...
- linux grep命令总结
风生水起善战者,求之于势,不责于人,故能择人而任势. 博客园 首页 新随笔 联系 订阅 管理 posts - 791, comments - 394, trackba ...
- linux grep 从入门到精通
linux grep 从入门到精通 一.初级 搜索日志 grep "186" catalina.out 在新输出日志中监听固定字符串 tail -f catalina.out | ...
- Linux grep命令详解[备份]
linux grep命令 1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressi ...
- linux grep命令(linux在文件中搜索内容)
转自:https://www.cnblogs.com/end/archive/2012/02/21/2360965.html linux grep命令 1.作用Linux系统中grep命令是一种强大的 ...
- linux grep 搜索查找
查找关键字在哪些文件夹中的哪些文件中出现(只列出文件名称): grep -l 15386257298 */* 查找关键字在哪些文件夹中的哪些文件中出现(列出文件名称+关键字): grep -o 153 ...
- linux grep 查询多行的方法
linux grep 查询多行的方法 经常查询 git log 中使用的方法, 如下 git log |grep "xxxx" 如果想查询多行的话, 就有些尴尬, 如果想查询多行的 ...
- linux grep的用法
linux grep的用法<pre>[root@iZ23uewresmZ ~]# cat /home/ceshis.txtb124230 b034325 a081016 m7187998 ...
随机推荐
- 转: Hibernate commit() 和flush() 的区别
[java] view plaincopyprint? <<精通Hibernate java对象持久化技术详解>> ,flush()方法进行清理缓存的操作,执行一系列的SQL语 ...
- IOS Core Animation Advanced Techniques的学习笔记(五)
第六章:Specialized Layers 类别 用途 CAEmitterLayer 用于实现基于Core Animation粒子发射系统.发射器层对象控制粒子的生成和起源 CAGradient ...
- js只保留整数,向上取整,四舍五入,向下取整等函数
1.丢弃小数部分,保留整数部分 parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3.四舍五入. Math.round(5/2) 4.向下取整 Math.f ...
- isMobile
var isMobile = { Android: function() { return navigator.userAgent.match(/Android/i); }, BlackBerry: ...
- web学习之开发环境的搭建
开发工具 myeclipse2014: tomcat7.0 jdk7.0 1:新建一个web projcat 2:找到web root目录下的index.jsp 这是项目首页 3:访问web项目 ht ...
- C++ 类模板的使用
从事C++挺久了,在前段时看书时,发现高手,都是在写模板无,泛型编程,顿感差距.自己连模板都没有写,于是就小小的研究了下模板的用法. 模板简而言之就是对某此对象的相同方法,或处理方式,进行归纳,总结, ...
- DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版原创发布-带官方示例程序版
关于 DotNetBar for Windows Forms 12.7.0.10_冰河之刃重打包版 --------------------11.8.0.8_冰河之刃重打包版------------- ...
- c语言-四阶龙格-库塔法
#include<stdio.h> #include<math.h> #define n 14 //double func1(double x, double y); doub ...
- people have been arrested under other offences instead.
Homosexuality is not explicitly banned in Egypt but gay people have been arrested under other offenc ...
- 初步了解JPA
想当初07.08年的时候,毕业之季,正思考着离开学校要去做什么工作.为了有一份薪资不错,可以长久发展,也正是自己喜欢的行业.于是乎决定投身于计算机行业.当年正是JAVA的火热时期.到处都是JAVA培训 ...