示例:
a)过滤以 root 开头的行, 过滤以 root 开头 bash 结尾的行
grep ^root testfile
root:x:0:0:root:/root:/bin/bash
grep -E "(^root|bash$)" testfile
root:x:0:0:root:/root:/bin/bash
b)过滤以 root 结尾的行
grep root$ testfile
test:test:root
c)搜索 e 开头 y 结尾的四字符单词
vim testfile1
eay
eby
eaay
ebby
eaaay
eaaaay
ebbbby
eababy
eaby
eabababy
grep e.y testfile1
eay
eby
grep e..y testfile1
eaay
ebby
eaby
d)搜索 e 开头 Y 结尾的所有行
```timeline
# 使用一级标题表示 timeline 的标题
## 2022-10-1
### 使用二级标题表示时间,三到六级标题表示内容
支持简单的 markdown 语法
- 这是无序列表项 1
- 这是无序列表项 2
---
支持 **加粗**,*斜体*,`代码`,~~删除~~,[链接](https://github.com/obgnail/typora_plugin),![图片](https://avatars.githubusercontent.com/u/48992887?s=96&v=4)
不支持代码块,因为开发者不希望代码块发生嵌套
## 2023-10-1
语法是开发者自定义的,谨慎使用。
grep e.*y testfile1
eay
eby
ebby
eaaay
ebbby
eaaaaay
ebbbbby
eababy
eaby
eabababy
c)搜索自定次数出现的字符
grep -E "e.{2}y" testfile1
eaay
ebby
eaby
grep -E "e.{,2}y" testfile1
eay
eby
ebby
eaby
grep -E "e.{2,}y" testfile1
eaay
ebby
eaaay
ebbby
eaaaaay
ebbbbby
eababy
eaby
eababy
grep -E "e.{2,3}y" testfile1
eaay
ebby
eaaay
ebbby
eaby
grep -E "e.?y" testfile1
eay
eby
grep -E "e.+y" testfile1
eay
eby
eaay
ebby
eaaay
ebbby
eaaaaay
ebbbbby
eababy
eaby
eabababy
grep -E "e [^ac]?y" testfile1
eby
grep -E "e [ac]?y" testfile1
eay
grep -E "e(ab)?y" testfile1
eaby