\r表示回车 \n表示换行
只显示匹配的字符串
grep -o
-v是取反的意思
[root@localhost ~]# grep -n 'the' 10.txt //显示有the的行,并且显示行号
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
4:The year ahead will test our political establishment to the limit.
[root@localhost ~]# grep -vn 'the' 10.txt
1:he was short and fat.
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
5:PI=3.141592653589793238462643383249901429
6:a wood cross!
7:Actions speak louder than words
8:
9:
10:#woood # #woooooood # AxyzxyzxyzxyzC
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
12:
13:I shouldn't have lett so tast.
[root@localhost ~]# grep -in 'the' 10.txt //不区分大小写过滤
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
4:The year ahead will test our political establishment to the limit.
[root@localhost ~]# grep -n 'sh[io]rt' 10.txt
1:he was short and fat.
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
[root@localhost ~]# grep -n 'oo' 10.txt
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
[root@localhost ~]# grep -n '[^w]oo' 10.txt //grep命令中的^不是开头的意思,而是取反的意思
2:He was wearing a blue polo shirt with black pants. The home ofFootball on BBC Sport online.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
10:#woood # #woooooood # AxyzxyzxyzxyzC
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
[root@localhost ~]# grep -n 'woo*d' 10.txt
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
[root@localhost ~]# grep -n 'w.*d' 10.txt //.的意思是匹配一个字符 ..是匹配两个字符 *重复前面字符0次或者多个前面的单字符
1:he was short and fat.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
6:a wood cross!
7:Actions speak louder than words
10:#woood # #woooooood # AxyzxyzxyzxyzC
[root@localhost ~]# grep -n '[0-9][0-9]*' 10.txt
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
5:PI=3.141592653589793238462643383249901429
[root@localhost ~]# grep -n 'o\{2\}' 10.txt
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
[root@localhost ~]# grep -n 'wo\{2,5\}d' 10.txt
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
[root@localhost ~]# grep -n 'wo\{2,\}d' 10.txt
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
+的作用
[root@localhost ~]# egrep -n 'wo+d' 10.txt
6:a wood cross!
10:#woood # #woooooood # AxyzxyzxyzxyzC
?的作用
[root@localhost ~]# egrep -n 'bes?t' 10.txt
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
|的作用
[root@localhost ~]# egrep -n 'of|is|on' 10.txt
2:He was wearing a blue polo shirt with black pants. The home of Football on BBC Sport online.
3:the tongue is boneless but it breaks bones.12! google is the best tools for search keyword.
4:The year ahead will test our political estabishment to the limit.
7:Actions speak louder than words
11:I bet this place is really spooky late at night! Misfortunes never come alone/single.
()的作用
[root@localhost ~]# egrep -n 't(a|b)st' 11.txt
13:I shouldn't have lett so tast.
()+的作用
[root@localhost ~]# egrep -n 'A(xyz)+C' 10.txt
10:#woood # #woooooood # AxyzxyzxyzxyzC
Sed工具概述
[root@localhost ~]# sed -n 'p' 10.txt //输出所有内容,等同于 cat 10.txt
[root@localhost ~]# sed -n '3p' 10.txt //输出第3行
[root@localhost ~]# sed -n '3p,5p' 10.txt //输出3~5行
[root@localhost ~]# sed -n 'p;n' 10.txt //输出所有奇数行,n表示读入下一行资料
[root@localhost ~]# sed -n ‘n;p’ 10.txt //输出所有偶数行,n表示读入下一行资料
[root@localhost ~]# sed -n '1,5{p;n}' 10.txt //输出第 1~5行之间的奇数行 (第1 ,3 ,5行)
[root@localhost ~]# sed -n '10,${n;p}' 10.txt //输出第10行至文件尾之间的偶数行 (注意10行视为1 然后往下依次排序 )
[root@localhost ~]# sed -n '/the/p' 10.txt //输出包含the 的行
[root@localhost ~]# sed -n'4,/the/p' 10.txt //输出从第4行至第一个包含the的行
从第四行开始找the,第四行也输出出来,顺带把没有the的行也全打印出来了直到遇到第一个the的行停止
[root@localhost ~]# sed -n '/the/=' 10.txt //输出包含the的行所在的行号,等号(=)用来输出行号
[root@localhost ~]# sed -n '/^PI/p' 10.txt //输出以PI开头的行
[root@localhost ~]# sed -n '/[0-9]$/p' 10.txt //输出以数字结尾的行
[root@localhost ~]# sed -n '/\<wood\>/p' 10.txt //输出包含单词wood的行