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 ...
随机推荐
- sql 多级内查询
最近在开发一个外包的项目,其中有个需求,一直困扰我好几天,今天终于找到了解决方案.大致需求如下:公司总部发货给经销商,其中经销商包含四种级别,钻石.金牌.银牌和铜牌,等级依次下发,钻石包含金牌,金牌包 ...
- 商品sku规格选择效果,没有商品的不能选中,选择顺序不影响展示结果
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- TF400324: Team Foundation services are not available from server…
Quick Fix As a quick fix you can Close Visual Studio and related apps Browse to %LocalAppData%\Micro ...
- gif显示
public void gifplay(string path,ref Panel panel) { try{ Bitmap animatedGif = new Bitmap(path ); Grap ...
- vultr vps服务器存在的7个优势及选择原因
原本准备在第一篇文章的时候完整的新注册账户的,但是考虑到对于这款VPS主机的了解,还是先整理这篇关于网络上和我自己在使用vultr vps主机产品的时候可能自认为的优势之处,这样可以加强很多新用户对于 ...
- java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException
问题描述: 严重: IOException while loading persisted sessions: java.io.WriteAbortedException: writing abort ...
- JS技术大全
事件源对象:event.srcElement.tagName event.srcElement.type 捕获/释放:event.srcElement.setCapture(); event.sr ...
- Linux 命令 find
find命令的基本格式是:find [路径] [选项] [操作]路径是find命令所查找的范围,如用.来表示当前目录,用/来表示根目录,选项用于指定查找条件,如:可以指定按照文件的属主,更改时间文件类 ...
- 关于 unsigned 型变量在计算过程中发生的事情
运行环境:CentOS release 5.8 (Final) #include<stdio.h> #include<iostream> using namespace std ...
- NC台网震相走时获取及 HYPOINVERSE 格式读取
HYPOINVERSE格式介绍:http://www.ncedc.org/ftp/pub/doc/man5/ncsn.phase.5 获取网站: http://www.ncedc.org/ncedc/ ...