标签:-bash targe inf ted 有一个 ima sel grep 基础
* 以什么开头
```
[root@wenhaha wenhaha]# cat wenhaha1.txt
123343 3423543 45345 345
wenhaha wenhaha wehan wehshdf
-bash: ech: command not found
[root@wenhaha wenhaha]# grep ‘^[0-9]‘ wenhaha1.txt
123343 3423543 45345 345
```
![](_v_images/20200316212020440_16128.png)
* 以什么结尾
```
[root@wenhaha wenhaha]# grep ‘[0-9]$‘ wenhaha1.txt
123343 3423543 45345 345
```
![](_v_images/20200316212158059_12744.png)
* 任意一个字符且只有一个字符
```
[root@wenhaha wenhaha]# grep ‘w.‘ wenhaha1.txt
wenhaha wenhaha wehan wehshdf
```
* 0个及0个以上的字符
```
[root@wenhaha wenhaha]# grep ‘h*‘ wenhaha1.txt
123343 3423543 45345 345
wenhaha wenhaha wehan wehshdf
-bash: ech: command not found
```
* 括号内的多个字符拆分匹配
[root@wenhaha wenhaha]# grep [h,m] wenhaha1.txt
whaha whaha wehan wehshdf
-bash: ech: command not found
* 排除括号内的字符
[root@wenhaha wenhaha]# grep [^0-9] wenhaha1.txt
123343 3423543 45345 345
whaha whaha wehan wehshdf
-bash: ech: command not found
* 表示或可以匹配多个字符
[root@wenhaha wenhaha]# egrep -v ‘^#|^$‘ /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
* 表示连续出现一次及以上
[root@wenhaha wenhaha]# egrep [0-9]+ wenhaha1.txt
123343 3423543 45345 345
* 括号内的字符整合
[root@wenhaha wenhaha]# ip a s eth0 |sed -rn ‘3s# .* (.*)/24.*$#\1#gp‘
192.168.1.223
* 指定匹配前一个字符连续出现了多次
[root@wenhaha wenhaha]# ip a s eth0 | egrep ‘([0-9]+.){3}[0-9]{3}‘ -o | head -1
192.168.1.223
标签:-bash targe inf ted 有一个 ima sel grep 基础
原文地址:https://www.cnblogs.com/wenhaha/p/12512571.html