regular_expression - HPECLab/tutorials GitHub Wiki
##Author: YangJian
##Email : [email protected]
#常用正则表达式命令
grep -n
显示行号
grep -n -A3 -B3
所匹配的行号附件上3行下3行也打印出来
grep -v
反向选择
grep -i
忽略大小写
grep 't[ae]st'
查找集合字符
grep '[^g]oo'
集合内反向选择
grep [^a-e]oo
集合内连续字符的反向选择
grep '^the '
匹配行首
grep '^[a-z]]'
匹配行首
grep '^[^a-zA-z]'
匹配开头非字母的行
grep '\.$'
匹配不以.结尾的行 .为特殊字符需要转义
grep '^$'
匹配空行
grep 'g..d'
.匹配单字符
grep 'oo*'
*重复前一个字符0到无穷次 如 oo ooo oooo
grep 'g.*g'
.*表示任意多个任意字符 如 good glag gog
grep 'o\{2\}'
匹配两个o { 为特殊字符需转义
grep 'go\{2,5\}g'
匹配2到5个o