Linux文本搜索比较命令-- grep/diff
2016-04-03 15:32
736 查看
---- GREP(1)
NAME:grep - Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE) 正则表达式
选项说明:
-n,--line-number : print line number with output files
-s,--no-messages : suppress error messages. 不显示错误信息
-v, --invert-match : select non-matching lines 取反操作,选择不匹配的输出。
-A,--after-context=NUM : print NUM lines of trailing context 输出context后的NUM行
-B,--before-context=NUM
: print NUM lines of leading context
-C,--context=NUM : print NUM lines of output context,上下NUM行都输出
-NUM same as --context=NUM
![](http://img.blog.csdn.net/20170830110746533)
命令cut用于基于列处理文本
-d,--delimiter 指定分割字符,默认是Tab
-f,--fields 指定输出的列号,某一行的域
-c,--character 基于字符进行分割
![](http://img.blog.csdn.net/20170830121434664)
-d:表示以:作为分隔符。
-c3-10表示显示第3~10个字符。
---- DIFF(1)
NAME:diff - compare files line by line
OPTION:
-i --ignore-case : Ignore case differences in file contents.
-E --ignore-tab-expansion : Ignore changes due to tab expansion. 忽略Tab键引起的变化
-b --ignore-space-change : Ignore changes in the amount of the white space. 忽略空格数量的变化
-w --ignore-all-space : Ignore all white space.忽略所有的空白
-B --ignore-blank-lines : Ignore changes whose lines are all blank. 忽略空白行
-c -C NUM --context [=NUM] : Output NUM (default 3) lines of copied context.
-u -U NUM --unified [=NUM] : Output NUM (default 3) lines of unified context. 统一显示比较信息
![](http://img.blog.csdn.net/20170416153037773)
![](http://img.blog.csdn.net/20170416154616354)
![](http://img.blog.csdn.net/20170416154630761)
NAME:grep - Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE) 正则表达式
选项说明:
-n,--line-number : print line number with output files
-s,--no-messages : suppress error messages. 不显示错误信息
-v, --invert-match : select non-matching lines 取反操作,选择不匹配的输出。
-A,--after-context=NUM : print NUM lines of trailing context 输出context后的NUM行
-B,--before-context=NUM
: print NUM lines of leading context
-C,--context=NUM : print NUM lines of output context,上下NUM行都输出
-NUM same as --context=NUM
命令cut用于基于列处理文本
-d,--delimiter 指定分割字符,默认是Tab
-f,--fields 指定输出的列号,某一行的域
-c,--character 基于字符进行分割
-d:表示以:作为分隔符。
-c3-10表示显示第3~10个字符。
[yanxia.dong@eslruntime07 exercise]$ grep -n yanxia.dong /etc/passwd 54:yanxia.dong:x:508:100::/home/yanxia.dong:/bin/bash [yanxia.dong@eslruntime07 exercise]$ grep -n -A3 yanxia.dong /etc/passwd 54:yanxia.dong:x:508:100::/home/yanxia.dong:/bin/bash 55-hailong.yu:x:509:100::/home/hailong.yu:/bin/tcsh 56-zezeng.feng:x:510:100::/home/zezeng.feng:/bin/bash 57-eslshare:x:511:100::/home/eslshare:/sbin/nologin [yanxia.dong@eslruntime07 exercise]$ grep -n -B3 yanxia.dong /etc/passwd 51-feifan.wang:x:505:100::/home/feifan.wang:/bin/bash 52-tao.gao:x:506:100::/home/tao.gao:/bin/csh 53-mengjiao.liu:x:507:100::/home/mengjiao.liu:/bin/bash 54:yanxia.dong:x:508:100::/home/yanxia.dong:/bin/bash [yanxia.dong@eslruntime07 exercise]$ grep -n -C3 yanxia.dong /etc/passwd 51-feifan.wang:x:505:100::/home/feifan.wang:/bin/bash 52-tao.gao:x:506:100::/home/tao.gao:/bin/csh 53-mengjiao.liu:x:507:100::/home/mengjiao.liu:/bin/bash 54:yanxia.dong:x:508:100::/home/yanxia.dong:/bin/bash 55-hailong.yu:x:509:100::/home/hailong.yu:/bin/tcsh 56-zezeng.feng:x:510:100::/home/zezeng.feng:/bin/bash 57-eslshare:x:511:100::/home/eslshare:/sbin/nologin [yanxia.dong@eslruntime07 exercise]$ grep -n -1 yanxia.dong /etc/passwd 53-mengjiao.liu:x:507:100::/home/mengjiao.liu:/bin/bash 54:yanxia.dong:x:508:100::/home/yanxia.dong:/bin/bash 55-hailong.yu:x:509:100::/home/hailong.yu:/bin/tcsh
---- DIFF(1)
NAME:diff - compare files line by line
OPTION:
-i --ignore-case : Ignore case differences in file contents.
-E --ignore-tab-expansion : Ignore changes due to tab expansion. 忽略Tab键引起的变化
-b --ignore-space-change : Ignore changes in the amount of the white space. 忽略空格数量的变化
-w --ignore-all-space : Ignore all white space.忽略所有的空白
-B --ignore-blank-lines : Ignore changes whose lines are all blank. 忽略空白行
-c -C NUM --context [=NUM] : Output NUM (default 3) lines of copied context.
-u -U NUM --unified [=NUM] : Output NUM (default 3) lines of unified context. 统一显示比较信息
相关文章推荐
- Linux常用命令
- 阿里云 ECS Linux 服务器中文乱码如何解决?
- linux 查看网卡相关信息
- Linux之ip命令
- Linux -- head/tail
- LINUX内核分析第六周学习总结——进程的描述与创建
- linux内核分析作业6:分析Linux内核创建一个新进程的过程
- CentOS安装中文支持包
- Linux内核分析:实验六--Linux进程的创建过程分析
- Linux下/etc/fstab文件详解
- Linux查看机器负载
- mesos 集群安装部署规划、准备(1)
- linux下vi编辑文件
- CentOS 7上安装Zabbix(快速安装监控工具Zabbix)
- linux下日期时间自动同步设置(rdate,ntpdate两种方法)
- 我们使用Linux的真正原因
- Linux安装rmp包,缺少依赖包安装教程
- 在Android Studio中安装OpenCV mac环境/Linux环境
- 为什么使用LINUX(有点长,没耐心别看)大家自己体会
- linux系统调用