【grep学习笔记】

test.txt 和test.txt2的内容【用于测试】:

111111

222222Test

333333test

444444TeSt

555555tesT

666666TEST

777777

888888

999999

-----------

-------------------------------------------------------------

-b 在每行前面加上找到它的块号。这对于按上下文查找块编号非常有用(第一个块为 0)。【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

 grep -b 99 test.txt         //output:     0:999999    所有数据都在第一个块中

-------------------------------------------------------------

-c 仅打印包含匹配结果的行的计数。【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

grep -c  99 test.txt         //output: 1

-------------------------------------------------------------

-h 阻止将包含匹配行的文件的名称追加到该行。 在搜索多个文件时使用。【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

grep  99 test.tx*           //文件名出现在输出行的最前面  

test.txt:999999

test.txt2:999999

grep -h  99 test.tx*        //文件名没有出现在输出结果中

999999

999999

-------------------------------------------------------------

-i 在比较过程中忽略大写/小写区分。【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

grep test test.txt*        //搜索结果的时候准确匹配了大小写

test.txt:333333test

test.txt2:333333test

grep -i test test.txt*    //搜索结果的时候忽略大小写

test.txt:222222Test

test.txt:333333test

test.txt:444444TeSt

test.txt:555555tesT

test.txt:666666TEST

test.txt2:222222Test

test.txt2:333333test

test.txt2:444444TeSt

test.txt2:555555tesT

test.txt2:666666TEST

-------------------------------------------------------------

-l 仅打印具有匹配行的文件名,以换行符分隔。 当多次找到模式时,不会重复文件名。【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

grep -l test test.txt*        //文件名已经去重

test.txt

test.txt2

grep -li  test test.txt*      //文件名已经去重, 即便结果出现在多行中

test.txt

test.txt2

-------------------------------------------------------------

-n 在每行前面加上文件中的行号(第一行为 1)【options are supported for both /usr/bin/grep and /usr/xpg4/bin/grep:】

grep -in test  tes

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值