鸟哥私房菜基础篇笔记04

 

[root@linux ~] grep ‘root’ /var/log/secure

      将这个文件中有root的那一行显示出来

[root@linux ~] grep –v ‘root’ /var/log/secure

将这个文件中没有root的那一行显示出来

[root@linux ~] grep –v ‘the ‘ test.txt

带有the的行,及其行号一起显示出来

[root@linux ~] grep –i ‘the ‘ test.txt

忽略大小写

[root@linux ~] grep –n[g^]oo’ test.txt

将文件中不是goo开头的那一行连同行号显示出来,但必须有oo,可以是foo,too但不是goo

`             [root@linux ~] grep –n[a-z^]oo’ test.txt

              不是小写英文字母+00字和的那一行

        [root@linux ~] grep –n[0-9]’ test.txt

        有数字的那一行

        [root@linux ~] grep –n^the’ test.txt

        单词the只出现在行首

[root@linux ~] grep –n^[a-z]’ test.txt

字母开头的行列出来

[root@linux ~] grep –n^[^a-Za-Z]’ test.txt

不是英文字母开头的

^[]外表示行首,[^]内表示反向选择

[root@linux ~] grep –n ‘\.$’ test.txt

表示以”.”结尾,由于”.”有特殊含义,所以用”\.”转义

[root@linux ~] grep –n ‘^$’ test.txt

将文本中的空行显示出来

[root@linux ~] grep –v ‘^$’ test.txt | grep –v ‘^#’

=[root@linux ~] egrep –v ‘^$|^#’ test.txt

不是空行和不是以#开头的行,即去注释和空行

0*表示拥有空字符或10以上的0

00*第一个0肯定是要存在的第二个0是可有可无的

[root@linux ~] grep –n ‘ooo*’ test.txt

文本中至少有2个连续的o列出来

[root@linux ~] grep –n ‘goo*g’ test.txt

文本中有至少一个o的行列出来

.*代表具有0个或至少一个字符

[root@linux ~] grep –n ‘g.*g’ test.txt

g开头和结束的字符

[root@linux ~] grep –n ‘[0-9] [0-9]*’ test.txt

具有数字的行

限定字符数

[root@linux ~] grep –n ‘0\{2\}’ test.txt

\为转义符号,对{}转义,表示文本中有20的行

[root@linux ~] grep –n ‘go\{2\5}g’ test.txt

G后面接2-5o,然后再接一个g的行

比较2个文件的差别

[root@linux ~] diff first.txt second.txt 用于文本文件

[root@linux ~] cmp first.txt second.txt 用于二进制文件

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值