Linux 文本处理工具 - grep(查找符合条件字符串)
简介
常用参数
参数 | 说明 |
---|
-E | 相当于 ‘egrep’,启用扩展正则表达 |
-i | 忽略大小写 |
-v | 反向过滤 |
-数字 | 显示过滤行及上面几行和下面几行 |
-n | 显示匹配的行所在行号 |
-A | 显示过滤行以及下面几行 |
-B | 显示过滤行以及上面几行 |
用法 | 说明 |
---|
^linux | 以linux开头 |
linux$ | 以linux结尾 |
w…s | w开头s结尾中间4个任意字符 |
…s | s结尾前面5个任意字符 |
* | 字符出现任意 |
.* | .为* |
o* | o为* |
用法 | 说明 |
---|
? | 0到1次 |
+ | 1次到任意次 |
{n} | n 次数 |
{m,n} | m到n次 |
{0,n} | 0-n次 |
{,n} | 0-n次 |
{m,} | 最少m次 |
(eg){2} | eg字符串出现2次 |
实例
[root@ grep]
> root
> rootlinux
> linuxroot
> ROOT
> roooot
> rot
> egegeg
> egeg
> EOF
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
[root@ grep]
[root@ grep]
root
rootlinux
[root@ grep]
[root@ grep]
root
linuxroot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
ROOT
[root@ grep]
[root@ grep]
root
rootlinux
[root@ grep]
[root@ grep]
root
linuxroot
[root@ grep]
[root@ grep]
roooot
rot
egegeg
[root@ grep]
[root@ grep]
6:rot
[root@ grep]
[root@ grep]
rot
egegeg
egeg
[root@ grep]
[root@ grep]
ROOT
roooot
rot
[root@ grep]
[root@ grep]
ROOT
roooot
rot
egegeg
egeg
[root@ grep]
- " r " 开头 " t "结尾 中间4个任意字符
[root@ grep]
roooot
[root@ grep]
[root@ grep]
linuxroot
roooot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
roooot
rot
[root@ grep]
[root@ grep]
rot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
roooot
rot
[root@ grep]
roooot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
roooot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
rot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
rot
[root@ grep]
[root@ grep]
root
rootlinux
linuxroot
roooot
[root@ grep]
[root@ grep]
egegeg
egeg
[root@ grep]