为了突出显示查询结果,将匹配到的内容上色
[root@localhost /]# alias 'grep=grep -n --color=auto '
一、 “.” 表示匹配一个字符,”*” 表示前边字符循环n次
[root@localhost /]# grep "s..d" zhengze.txt
i said
[root@localhost /]# grep "s.*d" zhengze.txt
i said
i sid saaad good
二、 “^” 表示行首,“$“ 表示行尾
[root@localhost /]# grep "^g" zhengze.txt
god is a Man
[root@localhost /]# grep "a$" zhengze.txt
haha
三、“[]” 表示包含任意一个数值的行 “[^]” 表示不包含
[root@localhost /]# grep "sa[axi]d" zhengze.txt
i said
saxd
[root@localhost /]# grep "sa[^x]d" zhengze.txt
i said
四、 “\” 表示转义符,用于取消特殊符号的含义
”{3\}” 表示出现三次
“{1,\}”出现最少1次 “{1,5\}”出现最少1次,最多5次
[root@localhost /]# grep "[0-9]\{3\}" zhengze.txt
123
1234