记得加上双引号:""
* 匹配前面的字符任意次,包括0次
贪婪模式:尽可能长的匹配
. 任意长度的任意字符
? 匹配其前面的字符0或1次
+ 匹配其前面的字符至少1次
{n} 匹配前面的字符n次
{m,n} 匹配前面的字符至少m次,至多n次
{,n} 匹配前面的字符至多n次
{n,} 匹配前面的字符至少n次*
例子
1.取IP地址(基础版)CentOS 7
ifconfig ens33 |grep -o "[0-9.]{7,}" |head -n1
ifconfig ens33 |grep -o "[[:digit:]]{1,3}.[[:digit:]]{1,3}[.][[:digit:]]{1,3}[.][[:digit:]]{1,3}" |head -n1
ifconfig ens33 |grep -o "inet [0-9.]+"|cut -d" " -f2
2.取最大磁盘利用率
df |grep "/dev/sd"|grep -o "[0-9]{1,3}%"|grep -o "[0-9]+"|sort -rn|head -1
df |grep "/dev/sd"|grep -o "[0-9]{1,3}%"|grep -o "[0-9]+"|sort -n|tail -1