linux系统中grep同时提取以特定字符开头的行、以特定字符结尾的行

1、

[root@centos79 test]# cat a.txt
a g r e
u c j alike
i x k like
a f g liker
a f h g liker
s g e g
[root@centos79 test]# grep "^a" a.txt   ## 查找以a开头的行
a g r e
a f g liker
a f h g liker
[root@centos79 test]# grep "^a.*r$" a.txt   ## 同时查找以a开头同时以r结尾的行
a f g liker
a f h g liker
[root@centos79 test]# grep "^a.*h.*r$" a.txt  ## 同时查找以a开头,包含字符h,并以r结尾的行
a f h g liker

2、

[root@centos79 test]# cat a.txt
a g r e
u c j alike
i x k like
a f g liker
a f h g liker
s g e g
[root@centos79 test]# grep "^a|e$" a.txt  ## 提取以a开头,或者以e结尾的行
a g r e
u c j alike
i x k like
a f g liker
a f h g liker
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14969695.html