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