Linux文本搜索比较命令-- grep/diff

---- 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


命令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. 统一显示比较信息



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值