1.不打印空行和注释行
grep -v -E '^#|^$' elasticsearch.yml
2.正则的特殊字符
?: "?"前面的字符只允许出现一次或者零次
[root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@?qq.com' aaa@qq.com [root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@?qq.com' aaaqq.com [root@manager1 shell]#
+: "+"前面的字符至少出现一次或者多次
[root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@+qq.com' [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@+qq.com' aaa@qq.com
*: "*"前面的字符可以出现0次或者多次
[root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}@*qq.com' aaa@qq.com [root@manager1 shell]# echo "aaaqq.com"|grep -E 'a{3}@*qq.com' aaaqq.com
| (管道符|):"|"类似于逻辑或or,可以用来过滤多个数据块
[root@manager1 shell]# echo "aaa#qq.com"|grep -E 'a{3}[@|#]qq.com' aaa#qq.com [root@manager1 shell]# echo "aaa@qq.com"|grep -E 'a{3}[@|#]qq.com' aaa@qq.com
()组合代码块: "()"可以将多个字符组合成一个代码块
[root@manager1 shell]# echo "aaaa@qq.com"|grep -E '^(aa){2}[@|#]qq.com' aaaa@qq.com
{}:"{}"可以指定字符串或者代码块重复几次或者几到几次,使用','来指定范围
[root@manager1 shell]# echo "aa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com' aa@qq.com [root@manager1 shell]# echo "aaaa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com' aaaa@qq.com [root@manager1 shell]# echo "aaaaaa@qq.com"|grep -E '^(aa){1,2}[@|#]qq.com'