1 aa
2 AA
3 Aa
4
5
[root@future tmp]# cat bo
1
2
sss bo-
3
4
5.8 shell 5 5
6
hello grep 5
1:1
2:2
3:sss bo-
4:3
5:4
6:5.8 shell 5 5
7:6
8:hello grep 5
1 aa
2 AA
3 Aa
bo
newbo
2
[root@future tmp]# grep -c -i 'a' newbo
3
5.8 shell 5 5
[root@future tmp]# grep -w 'hell' bo
[root@future tmp]#
1 aa
2 AA
3 Aa
4
5
[root@future tmp]# grep -A2 '3' newbo 下两行
3 Aa
4
5
[root@future tmp]# grep -B2 '3' newbo 上两行
1 aa
2 AA
3 Aa
[root@future tmp]# grep -C2 '3' newbo 上下各两行
1 aa
2 AA
3 Aa
4
5
[root@future tmp]#
0:1 aa
6:2 AA
12:3 Aa
18:4
20:5
1
2
[root@future tmp]# grep -f regular newbo -f 是指从文件中读取模板
1 aa
2 AA
[root@future tmp]#
bo:1
bo:2
bo:sss bo-
bo:3
bo:4
bo:5.8 shell 5 5
bo:6
bo:hello grep 5
newbo:1 aa
newbo:2 AA
newbo:3 Aa
newbo:4
newbo:5
regular:1
regular:2
[root@future tmp]# grep -h '' * -h 使得grep不打印头信息,这个例子中是不打印文件名
1
2
sss bo-
3
4
5.8 shell 5 5
6
hello grep 5
1 aa
2 AA
3 Aa
4
5
1
2
[root@future tmp]# echo $?
0
[root@future tmp]#
1
2
sss bo-
3
4
5.8 shell 5 5
6
hello grep 5
[root@future root]# cat nu
1
ss -bo
2
xx bo-
2222222222
3
4
bo:2
nu:2
nu:2222222222
bo:5.8 shell 5 5
5.8 shell 5 5
hello grep 5
5.8 shell 5 5
2
3
sss bo-
5.8 shell 5 5
hello grep 5
[root@future root]# grep '[^0-9]' bo
sss bo-
5.8 shell 5 5
hello grep 5
[root@future root]# grep "[^0-9]" bo
sss bo-
5.8 shell 5 5
hello grep 5
sss bo-
hello grep 5
5.8 shell 5 5
hello grep 5
[root@future root]# grep '^[a-z]\{5\}' bo打印开头字符串至少有5个连续小写字母的字符串的行
hello grep 5
5.8 shell 5 5
[root@future root]# grep '\(5\)\.[0-9] \1 .*\1' bo
[root@future root]# grep '\(5\)\.[0-9] .* \1 *\1' bo
5.8 shell 5 5
hello grep 5
5.8 shell 5 5
hello grep 5
[root@future root]# grep '\<hello\>' bo 打印所有包含单词hello的行
hello grep 5
hello grep 5
[root@future root]# grep '\hello\b' bo \b是单词分界符 没有理解这个参数请路过的高人注解
hello grep 5
hello grep 5
sss bo-
hello grep 5
hello grep 5
[root@future root]# grep '\<[a-z]\{5\}o\>' bo
[root@future root]# grep '\<[a-z]\{3,20\}o\>' bo
hello grep 5
[root@future root]# grep '\<[a-z]\{6,20\}o\>' bo
[root@future root]# grep '\<[a-z]\{5,20\}o\>' bo
[root@future root]#
[root@future root]# grep '\<[a-z]\{4,20\}o\>' bo 重复4次
hello grep 5
[root@future root]# grep '\<[a-z]\{5,6\}o\>' bo
[root@future root]# grep '2\|3' bo 加上反斜杠,这个字符就被翻译成扩展正则表达式。
2
3
2
3
5.8 shell 5 5
5.8 shell 5 5
adlkf adfkl aa 566.5
dfad 234.43 aaa
234 aaaa
adf adfa adf adf 45.556 aaaaa
[root@test-linux tmp]#
[root@test-linux tmp]#
[root@test-linux tmp]#
[root@test-linux tmp]# grep '\baaa\b' te \b 单词分界符
dfad 234.43 aaa
[root@test-linux tmp]#
adlkf adfkl aa 566.5
dfad. 234.43 aaa
dfad . 234.43 aaa
234 aaaa
adf adfa adf adf 45.556 aaaaa
[root@test-linux tmp]#
[root@test-linux tmp]#
[root@test-linux tmp]#
[root@test-linux tmp]# grep '^d\w' te \w 字母数字字符[a-zA-Z0-9] \W 非字母数字字符
dfad. 234.43 aaa
dfad . 234.43 aaa
[root@test-linux tmp]#