+ -
当前位置:首页 → 问答吧 → grep 中括号匹配问题

grep 中括号匹配问题

时间:2011-07-08

来源:互联网

  1. [root@localhost test]# cat file
  2. ccccbbbbbb
  3. cccc:bbbbbb
  4. caaab:bbbbb

  5. DDDE
  6. "DDD
  7. caaabd2
  8. 12245ttttt
  9. 2224455
复制代码
1、grep大写字母会把小写字母也查找出来
  1. [root@localhost test]# cat file | grep [A-Z]
  2. ccccbbbbbb
  3. cccc:bbbbbb
  4. caaab:bbbbb
  5. DDDE
  6. "DDD
  7. caaabd2
  8. 12245ttttt
复制代码
2、而如果匹配非的话,则会把非全部为字母(不管大写或者小写)的都匹配出来
  1. [root@localhost test]# cat file | grep [^A-Z]
  2. cccc:bbbbbb
  3. caaab:bbbbb
  4. "DDD
  5. caaabd2
  6. 12245ttttt
  7. 2224455
复制代码
还请哪位大侠帮忙解释一下为什么?

作者: bujipeng   发布时间: 2011-07-08