Linux中的方括号字符集:
[:digit:] 数字字符,0-9;
[:lower:] 小写字母字符,a-z;
[:upper:] 大写字母字符,A-Z;
[:alpha:] 大小写字母字符,A-Za-z;
[:alnum:] 数字、字母字符,0-9A-Za-z;
[:space:] 空白(whitespace)字符;
[:blank:] 空格(space)与定位(tab)字符;
[:graph:] 非空格(nospace)字符;
[:punct:] 标点符号字符;
[:print:] 可打印字符;
[:cntrl:] 控制字符;
[:xdigit:] 十六进制字符;
测试文件:
[root@ilinux ~]# cat test 123 123 abc abc #此行有空格; abc123 ABC ABC abc ABC123 123 abC a,b.c #此行无空格; AAbb.
示例1:[:digit:] 数字字符,0-9;
[root@ilinux ~]# grep ‘[[:digit:]]‘ test 123 123 abc abc123 ABC123 123 abC
示例2:[:lower:] 小写字母字符,a-z;
[root@ilinux ~]# grep ‘[[:lower:]]‘ test 123 abc abc abc123 ABC abc 123 abC a,b.c AAbb.
示例3:[:upper:] 大写字母字符,A-Z;
[root@ilinux ~]# grep ‘[[:upper:]]‘ test ABC ABC abc ABC123 123 abC AAbb.
示例4:[:alpha:] 大小写字母字符,A-Za-z;
[root@ilinux ~]# grep ‘[[:alpha:]]‘ test 123 abc abc abc123 ABC ABC abc ABC123 123 abC a,b.c AAbb.
示例5:[:alnum:] 数字、字母字符,0-9A-Za-z;
[root@ilinux ~]# grep ‘[[:alnum:]]‘ test 123 123 abc abc abc123 ABC ABC abc ABC123 123 abC a,b.c AAbb.
示例6:[:space:] 空白(whitespace)字符;
[root@ilinux ~]# grep ‘[[:space:]]‘ test 123 abc ABC ABC abc 123 abC
示例7:[:blank:] 空格(space)与定位(tab)字符;
[root@ilinux ~]# grep ‘[[:blank:]]‘ test 123 abc ABC ABC abc 123 abC
示例8:[:graph:] 非空格(nospace)字符;
[root@ilinux ~]# grep ‘[[:graph:]]‘ test 123 123 abc abc abc123 ABC ABC abc ABC123 123 abC a,b.c AAbb.
示例9:[:punct:] 标点符号字符;
[root@ilinux ~]# grep ‘[[:punct:]]‘ test a,b.c AAbb.
本文出自 “ilinux” 博客,请务必保留此出处http://shenzhijin.blog.51cto.com/1741240/1865291
原文地址:http://shenzhijin.blog.51cto.com/1741240/1865291