linux 常用命令 - grep

匹配多个关键词

用法:grep -E ‘your regular expression’ file
举例:我们拿冰与火之歌第七季第七集的部分字幕举个例子。

GameOfThrones.txt

30
00:04:14,370 --> 00:04:19,370
{\an8}{\pos(94.16,212.825)}app.YYeTs.com

37
00:00:08,070 --> 00:00:11,100
Little Theon! Come and get her.

38
00:00:19,300 --> 00:00:22,650
It's an invitation... to King's Landing.

39
00:00:22,650 --> 00:00:25,820
You will represent my interests at this gathering as you see them.

40
00:00:25,820 --> 00:00:28,540
It's not safe leaving you with Littlefinger.

41
00:00:28,540 --> 00:00:29,870
She's your sister.

匹配GameOfThrones.txt中含有’sister’或’King’的行

[~/shell]$ grep -E 'sister|King' GameOfThrones.txt
It's an invitation... to King's Landing.
She's your sister.

匹配GameOfThrones.txt中含有’sister’或’King’或’Little Theon’的行

注意’Little Theon’中间有个空格,这个时候就要用到正则表达式了Little.Theon,正则表达式中.代表任意字符。

[~/shell]$ grep -E 'sister|King|Little.Theon' grep2.txt
Little Theon! Come and get her.
It's an invitation... to King's Landing.
She's your sister.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值