grep 文本过滤
1.命令功能
grep, egrep, fgrep - print lines matching a pattern 根据匹配模式空间(正则表达式)打印结果行。
2.语法格式
grep [option] [pattern] [file]
grep 选项 模式 文件
grep [option] [-e pattern | -f file] [file]
grep 选项 增强正则 文件
grep选项说明
参数 |
参数说明 |
-E |
后面接的匹配模式就是扩展正则表达式 grep –E =egrep |
-i |
比较字符时忽略大小写区别 |
-w |
只匹配过滤出的单词。把表达式作为词来查找,相当于正则中的”\<..\>” |
-x |
被匹配到的内容,正好是整个行,相当于正则”^...$” |
-v |
取反,输出的内容与定于模式相反的内容 |
-c |
count统计,统计配结果的行数 |
-o |
只显示匹配的内容,该行的其他内容不输出 |
-R |
递归匹配。主要匹配目录下的多个文件内容 |
3.使用范例
[root@localhost ~]# cat passwd
root:x:0:0:root:/root:/bin/bash
suroot : X:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
adm:x::ADM:/var/adm:/sbin/nologin
Adm:x:3:4:abmIn:/var/adm:/sbin/nologin
lp x lp var/spool/lpd:/sbin/
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
示例1 匹配以‘axm’,a开始,m结束,中间任意字符的行
示例2 查询以root开头的行
示例3 查找以bash结尾的行
示例4 查找包含A或p字符的行
示例5 查找不包换a-z和B-Z的内容
示例6 只查询特殊字符,不包括字母,数字
grep 文本过滤的更多相关文章
- grep&正则表达式
p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; text-align: justify; f ...
- 正则和grep——再做正则就去死
grep 文本过滤工具 基本正则表达式 grep 语法 基本正则表达式的元字符 次数匹配 位置锚定 分组 扩展正则表达式 基本正则表达式的元字符 次数匹配 位置锚定 分组 或者 grep的介绍 lin ...
- grep命令.md
grep命令 简介 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Prin ...
- grep文本处理工具
grep是一款文本过滤工具,基于正则表达式进行模式匹配sed:stream editor 流编辑器awk:linux上实现为gawk,文本报告生成器(格式化文本)文本搜索工具,根据用户指定的模式,对目 ...
- LINUX系统下的shell命令---grep、sed、awk
1)grep文本过滤命令 1.grep基本认识 (Global search regular expression and print out the line全局搜索研究正则表达时并显示出 ...
- grep,cut,wc,sort,diff,uniq,patch命令
文本处理工具: Linux上文本处理三剑客: grep,egrep,fgrep: 文本过滤工具(模式: pattern)工具; grep:基本正则表达式,-E,-F egrep:扩展正则表达式,-G, ...
- shell脚本基础和grep文本处理工具企业应用4
文本处理工具: egrep: 支持扩展的正则表达式实现类似于grep文本过滤功能:grep -E egrep [OPTIONS] PATTERN [FILE...] ...
- 文本处理工具(cut,sort,tr,grep等)
命令目录,查看某一个命令可点击直接跳转: 文件查看 cat tac rev more less 按行截取 head tail 转化内容 tr 按列操作 cut paste 分析文本 wc sort u ...
- 正则表达式grep学习(一)
文本处理三剑客grep 文本过滤sed 流过滤awk 格式处理 正则表达式就是一些特殊字符组成的模式,赋予了他特定的含义 在大多数程序里,正则表达式都被置于两个正斜 ...
随机推荐
- java统计文档中相同字符出现次数(超详细)
public class test { public static void main(String[] args) throws Exception { InputStream file = new ...
- List of Mozilla-Based Applications
List of Mozilla-Based Applications The following is a list of all known active applications that are ...
- inode节点号
查看分区信息命令 df -Th 查看文件inode节点号 ls -i b.txt 查看系统中与b.txt 的inode节点号相同的所有文件,即硬链接 find / -inum xxxx(b.tx ...
- loj#6038 「雅礼集训 2017 Day5」远行
分析 代码 #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define ...
- __file__, sys._getframe().f_lineno 当前文件的行号
当前文件的行号 try: f = open(sys.argv[1], "rb") address_book.ParseFromString(f.read()) f.close()e ...
- mysql查询时特殊字符转译
commons.lang String value = StringEscapeUtils.escapeSql(searchRequest.getSearchValue());
- RESR API (二)之Responses
Responses 与基本的HttpResponse对象不同,TemplateResponse对象保留 the details of the context that was provided by ...
- linux 安装 sudo
1.安装sudo# apt-get install sudo2.修改 /etc/sudoers 文件属性为可写# chmod +w /etc/sudoers3.编辑 /etc/sudoers ,添加如 ...
- 【MM系列】SAP MM模块-BOM展开函数
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-BOM展开函数 ...
- 【Qt开发】Qt Creator在Windows上的调试器安装与配置
Qt Creator在Windows上的调试器安装与配置 如果安装Qt时使用的是Visual Studio的预编译版,那么很有可能就会缺少调试器(Debugger),而使用MSVC的Qt对应的原生调试 ...