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 ...
随机推荐
- 【图像处理】【SEED-VPM】1.板子基本操作流程
>>>>>>>>>>>>>>>>>>>>>>>>> ...
- Linq to entities 学习笔记
Linq to entities ---提供语言集成查询支持用于在概念模型中定义的实体类型. 首先可以根据http://msdn.microsoft.com/en-us/data/jj206878该 ...
- Web安全
随着Web2.0.网络社交等一系列新型的互联网产品的诞生,基于Web环境的互联网应用越来越广泛,企业信息化的过程中,越来越多的应用都架设在Web平台上.Web业务的迅速发展吸引了黑客们的强烈关注,接踵 ...
- TRANSPOSE的DATA步实现
data a; input name $ a b ; cards; x x x y y y ; run; %macro transpose; proc sql noprint ; select cou ...
- 节点操作js jQuery
append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在被选元素之后插入内容 before() - 在被选元素之前插入内容 functi ...
- wx jssdk
public static Dictionary<string,string> jsstr(string url) { //noncestr ); //timestamp TimeSpan ...
- Python时区转换
最近工作中遇到了一个问题:我的server和client不是在一个时区,server时区是EDT,即美国东部时区,client,就是我自己的电脑,时区是中国标准时区,东八区.处于测试需要,我需要向se ...
- python 中的高级函数sorted()
Python内置的 sorted()函数可对list进行排序: >>>sorted([36, 5, 12, 9, 21]) [5, 9, 12, 21, 36] 但 sorted() ...
- Android事件分发机制(上)
Android事件分发机制这个问题不止一个人问过我,每次我的回答都显得模拟两可,是因为自己一直对这个没有很好的理解,趁现在比较闲对这个做一点总结 举个例子: 你当前有一个非常简单的项目,只有一个Act ...
- CSS之过渡简单应用—日落西山
代码: <!DOCTYPE html><html><head> <title>日落西山</title> <meta charset=& ...