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 ...
随机推荐
- PHP注册审核做法
1.注册页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- json转类
JavaScriptSerializer js = new JavaScriptSerializer();T detaile = js.Deserialize<T>(json);
- HashBytes(Transact-SQL)
返回其输入的MD2.MD4.MD5.SHA或SHA1哈希值 语法 HashBytes('<algorithm>',{@input|'input'}) <algorithm>:: ...
- ZOJ 3817Chinese Knot(The 2014 ACM-ICPC Asia Mudanjiang Regional First Round)
思路: 将4个串每个串都反向这样得到新的四个串一共8个串,对于母串每个位置检测这个串能不能放进去,hs或者后缀数组都可以.然后dp[i][j] (0<i<len 0<=j< ...
- django:field字段类型
字段类型(Field types) AutoField 它是一个根据 ID 自增长的 IntegerField 字段.通常,你不必直接使用该字段.如果你没在别的字段上指定主 键,Django 就会自动 ...
- java 排序
class Employee { private String name; private String id; private String salary; public static void m ...
- html5移动web开发笔记(一)Web 存储
localStorage - 没有时间限制的数据存储 localStorage 方法 localStorage 方法存储的数据没有时间限制.第二天.第二周或下一年之后,数据依然可用. 用户访问页面的次 ...
- 两台装有Ubuntu系统的服务器搭建VPN(一台为本地服务器,另一台为云服务器)
我们搭建VPN采用的是openvpn,搭建过程总体需要经过三大步骤: 1.openvpn的安装与配置 2.端口转发 3.系统重启iptables规则自动生效 注意:以下所有名令在ro ...
- VIM神器打造Javascript开发环境
http://xuyufish.com/vim%E7%A5%9E%E5%99%A8%E6%89%93%E9%80%A0javascript%E5%BC%80%E5%8F%91%E7%8E%AF%E5% ...
- 黑马程序员——C语言基础 变量类型 结构体
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)变量类型 1)局部变量 1> 定义:在函数内部定义的变量,称为 ...