grep 同时查找多个文件

说明

有时候难免会遇到 想同时处理 多个文件的 情况,但其他情况使用都很正常,比如touch file1 file2 … mkdir file1 file2 同时写空多个文件…. 这些都行 , 直到有一天 我想grep 多个条件打印到屏幕,才发现 竟然不行 几经波折 整理出了 grep和egrep的方法!!!!
以touch为例,正常情况如下:
在这里插入图片描述
grep错误的就不一一展示了。。。。 感兴趣的 可以先不看我下面列出的方法,自行尝试一下哦!!!!

grep 和 grep –E(egrep)实现方法

grep格式

命令格式:grep ‘file1\|file2\|file3….’ # 注意有单引号
如:[root@control test]$ls |grep 'test1\|test2\|test3\|test4'
在这里插入图片描述

egrep格式

egrep和grep –E 是一样的功能 原因我就不做解释了!
命令格式:grep –E ‘file1|file2|file3’ or egrep ‘file1|file2|file3’
如:[root@control test]$ls | egrep 'test1|test2|test3|test4' [root@control test]$ls | grep -E 'test1|test2|test3|test4'

在这里插入图片描述

发布了98 篇原创文章 · 获赞 66 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/cuichongxin/article/details/105248788
今日推荐