【linux命令】

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

  1. 编写正则表达式匹配密码强度
    强密码(字母、数字和特殊符号三种组合,长度8位以上)
    弱密码(字母或数字或特殊符号,长度6位到8位)

  2. 查找test文件中包含go*gle 的行数据,
    显示行号和前后2行数据,并把查询结果保存到 google.txt 文件中


  1. a-zA-Z0-9_- ↩︎

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值