linux grep多条件匹配数据

1、创建测试数据

[root@linuxprobe test3]# cat a.txt
w r t f
s 4 6 6
a g g s
d g r 4
d e w h
s f g h

 

2、

[root@linuxprobe test3]# grep -E '^w|^a|h$' a.txt  ## 提取以w开头或者以a开头或者以h结尾的行
w r t f
a g g s
d e w h
s f g h

 

 

3、

[root@linuxprobe test3]# grep -E 'f|^a|h$' a.txt  ## 提取包含f的行或者以a开头的行或者以h结尾的行
w r t f
a g g s
d e w h
s f g h

 

 

4、

[root@linuxprobe test3]# grep '^d' a.txt | grep 'h$' ##提取同时满足以d开头,同时以h结尾的行
d e w h

 

posted @ 2020-10-11 21:45  小鲨鱼2018  阅读(1457)  评论(0编辑  收藏  举报