grep [选项] ‘关键字’ 文件名
#忽略大小写匹配包含 root 的行
grep -i ‘root’ passwd
#精确匹配 ftp 单词
grep -w ‘ftp’ passwd
#打印匹配到 root 关键字的行号
#忽略大小写匹配以 root 关键字开头的行号
#匹配包含 mail 关键字及其后5行
#匹配包含 mail 关键字及其前5行
#匹配包含 mail 关键字及其前后5行
word 匹配指定字符串(word)的值
^word 匹配以指定字符串开头的值 grep -n ‘^#’ test.txt
word$ 匹配以指定字符串结尾的值 grep -n ‘!KaTeX parse error: Expected group as argument to '\.' at position 285: …义去除 grep –n '\.'̲ test.txt x|y …’
“Open Source” is a good mechanism to develop programs.
apple is my favorite food.
Football game is not use feet only.
GO
good
this dress doesn’t fit me.
However, this dress is about $ 3183 dollars.^M
GNU is free air not free beer.^M
Her hair is very beauty.^M
I can’t finish the test.^M
Oh! The soup taste good.^M
motorcycle is cheap than car.
This window is clear.
the symbol ‘*’ is represented as start.
Oh! My god!
The gd software is a library for drafting programs.^M
You are the best is mean you are the no. 1.
The world is the same with “glad”.
I like dog.
google is the best tools for search keyword.
goooooogle yes!
GO GOgo! go! Let’s go.
GO
I am Bobby
- 量词,匹配指定内容 零次或无穷次 grep -n ‘ess*’ test.txt
? 量词,匹配指定内容 零次或一次 egrep -n ‘ess?’ test.txt
- 量词,匹配指定内容 一次或多次 egrep -n ‘ess+’ test.txt
{n} 量词:匹配指定内容 n次 grep -n ‘go{2}g’ test.txt,使用egrep 可以不用转义
{n,m} 量词:匹配指定内容 n次到m次 grep -n ‘go{2,3}g’ test.txt
{n,} 量词:匹配指定内容 n次到无穷次 grep -n ‘go{2,}g’ test.txt
注册
用户名 大小字母数字_-组合,3-6位 [a-zA-Z0-9_-]{3,6}
昵称
邮箱 admin12@qq.com @
手机 ^1[2-9][0-9]{9}$
密码
密保
1+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$
grep delegate /etc/* 2> /dev/null
-
编写正则表达式匹配密码强度
强密码(字母、数字和特殊符号三种组合,长度8位以上)
弱密码(字母或数字或特殊符号,长度6位到8位) -
查找test文件中包含go*gle 的行数据,
显示行号和前后2行数据,并把查询结果保存到 google.txt 文件中
a-zA-Z0-9_- ↩︎