linux 常用命令

来源:互联网 发布:淘宝30天历史最低价 编辑:程序博客网 时间:2024/06/16 18:31

匹配多个关键词

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

GameOfThrones.txt

3000:04:14,370 --> 00:04:19,370{\an8}{\pos(94.16,212.825)}app.YYeTs.com3700:00:08,070 --> 00:00:11,100Little Theon! Come and get her.3800:00:19,300 --> 00:00:22,650It's an invitation... to King's Landing.3900:00:22,650 --> 00:00:25,820You will represent my interests at this gathering as you see them.4000:00:25,820 --> 00:00:28,540It's not safe leaving you with Littlefinger.4100:00:28,540 --> 00:00:29,870She's your sister.

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

[~/shell]$ grep -E 'sister|King' GameOfThrones.txtIt'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.txtLittle Theon! Come and get her.It's an invitation... to King's Landing.She's your sister.
原创粉丝点击