-E, --extended-regexp PATTERN 是一个可扩展的正则表达式(缩写为 ERE)
-F, --fixed-strings PATTERN 是一组由断行符分隔的长字符串
-f, --file=FILE 从 FILE 中取得 PATTERN
-r, --recursive like --directories=recurse
-L, --files-without-match print only names of FILEs containing no match
-l, --files-with-matches print only names of FILEs containing matches
tee 命令用于读取标准输入的数据,将内容输出到屏幕,同时保存成文件,并且可以保存到多个文件。
-a, --append 内容追加到给定的文件末尾而非覆盖
不假 -a 则覆盖文件内容
先创建件文件,下面是文件插入的内容,右边是文件名。
[root@kafka-node2 what]# printf "%s are very cute. \n" cats dog catsggg ddd gggg 1111 2222 gggg |tee 1.txt 2.txt 3.txt 4.txt
[root@kafka-node2 what]# grep -rn "" ./* | sed -r "/8/a \ "
./1.txt:1:cats are very cute.
./1.txt:2:dog are very cute.
./1.txt:3:catsggg are very cute.
./1.txt:4:ddd are very cute.
./1.txt:5:gggg are very cute.
./1.txt:6:1111 are very cute.
./1.txt:7:2222 are very cute.
./1.txt:8:gggg are very cute.
./2.txt:1:cats are very cute.
./2.txt:2:dog are very cute.
./2.txt:3:catsggg are very cute.
./2.txt:4:ddd are very cute.
./2.txt:5:gggg are very cute.
./2.txt:6:1111 are very cute.
./2.txt:7:2222 are very cute.
./2.txt:8:gggg are very cute.
./3.txt:1:cats are very cute.
./3.txt:2:dog are very cute.
./3.txt:3:catsggg are very cute.
./3.txt:4:ddd are very cute.
./3.txt:5:gggg are very cute.
./3.txt:6:1111 are very cute.
./3.txt:7:2222 are very cute.
./3.txt:8:gggg are very cute.
./4.txt:1:cats are very cute.
./4.txt:2:dog are very cute.
./4.txt:3:catsggg are very cute.
./4.txt:4:ddd are very cute.
./4.txt:5:gggg are very cute.
./4.txt:6:1111 are very cute.
./4.txt:7:2222 are very cute.
./4.txt:8:gggg are very cute.
在新建一个文件和上面内容不相同。。。。。
[root@kafka-node2 what]# printf "%s are very cute. \n" faker uzi Clearlove7 xiaoming dajiuzi |tee 5.txt
[root@kafka-node2 what]# cat 5.txt
faker are very cute.
uzi are very cute.
Clearlove7 are very cute.
xiaoming are very cute.
dajiuzi are very cute.
--------------------------------------------------------------------------------------------------------
-F, --fixed-strings PATTERN 是一组由断行符分隔的长字符串
-r, --recursive like --directories=recurse (递归查找目录下文件是否有你想要找的内容)
pwd ----- 打印当前所在的目录
[root@kafka-node2 inity]# pwd;ls;ls what
/root/inity
what what.txt
1.txt 2.txt 3.txt 4.txt 5.txt
不加-r参数是查找当前目录下是否有你想要找的内容
[root@kafka-node2 inity]# grep "gggg" ./*
grep: ./what: 是一个目录
./what.txt:gggg are very cute.
./what.txt:gggg are very cute.
加了-r 递归查找目录下文件是否有你想要找的内容)
[root@kafka-node2 inity]# grep -r "gggg" ./*
./what/1.txt:gggg are very cute.
./what/1.txt:gggg are very cute.
./what/2.txt:gggg are very cute.
./what/2.txt:gggg are very cute.
./what/3.txt:gggg are very cute.
./what/3.txt:gggg are very cute.
./what/4.txt:gggg are very cute.
./what/4.txt:gggg are very cute.
./what.txt:gggg are very cute.
./what.txt:gggg are very cute.
------------------------------------------------------------------------------------------------
-l, --files-with-matches print only names of FILEs containing matches (打印你匹配到内容的文件名,一般和-r一起用)
[root@kafka-node2 inity]# grep -rl "gggg" ./*
./what/1.txt
./what/2.txt
./what/3.txt
./what/4.txt
./what.txt
--------------------------------------------------------------------------------------------------
-L, --files-without-match print only names of FILEs containing no match(与-l相反打印你没匹配到的文件名)
[root@kafka-node2 inity]# grep -rL "gggg" ./*
./what/5.txt
--------------------------------------------------------------------------------------------------
-f, --file=FILE 从 FILE 中取得 PATTERN(匹配文件第一个文件和第二文件相同的内容)
[root@kafka-node2 what]# more 1.txt
cats are very cute.
1111111111111111111
dog are very cute.
catsggg are very cute.
ddd are very cute.
gggg are very cute.
1111 are very cute.
2222 are very cute.
gggg are very cute.
[root@kafka-node2 what]# more 2.txt
cats are very cute.
dog are very cute.
catsggg are very cute.
ddd are very cute.
gggg are very cute.
1111 are very cute.
2222 are very cute.
gggg are very cute
文件1.txt中1111111111111111111 2.txt 没有,所以没有打印
[root@kafka-node2 what]# grep -f 1.txt 2.txt
cats are very cute.
dog are very cute.
catsggg are very cute.
ddd are very cute.
gggg are very cute.
1111 are very cute.
2222 are very cute.
gggg are very cute.
---------------------------------------------------------------------------------------------------
-E, --extended-regexp PATTERN 是一个可扩展的正则表达式(缩写为 ERE) (grep -E 与egrep相似)
grep -E 支持更多的元字符,即egrep使用的是拓展的正则表达式(grep -F 也可以写成 egrep )
不加-E,下述的命令匹配则需要加 转义符"\"
[root@kafka-node2 what]# grep "gggg\|2222" 1.txt
gggg are very cute.
2222 are very cute.
gggg are very cute.
加 -E 则不需要
[root@kafka-node2 what]# grep -E "gggg|2222" 1.txt
gggg are very cute.
2222 are very cute.
gggg are very cute.
----------------------------------------------------------------------------------------------------
-F, --fixed-strings PATTERN 是一组由断行符分隔的长字符串 ,意思就是匹配啥内容就匹配什么的内容
不会去解释正则表达,元字符之类,也就是你匹配内容(grep -F 也可以写成fgrep 效果差不多)
[root@kafka-node2 what]# cat 1.txt
cats are very cute.
1111111111111111111
dog are very cute.
catsggg are very cute.
ddd are very cute.
gggg are very cute.
1111 are very cute.
2222 are very cute.
gggg are very cute.
^1111111
[ dasda fdafafafa]
不加-F,匹配的内容如下
[root@kafka-node2 what]# grep "^1111111" 1.txt
1111111111111111111
加了-F,匹配的内容如下
[root@kafka-node2 what]# grep -F "^1111111" 1.txt
^1111111