Chinaunix

标题: 看不懂这个命令的输出: "egrep '4(ab)?' a.txt" [打印本页]

作者: ubuntun    时间: 2007-12-15 23:47
标题: 看不懂这个命令的输出: "egrep '4(ab)?' a.txt"
a.txt文件的内容如下:
hello
4a
4b
4c
4d
4e
4f
4g
4h
4t
4ab
4bc
4th
4abc
4bcd
1234
[9-1]

可是为什么"egrep '4(ab)?' a.txt"命令的输出结果是这样呢?

  1. ~/tmp$ egrep '4(ab)?' a.txt
  2. 4a
  3. 4b
  4. 4c
  5. 4d
  6. 4e
  7. 4f
  8. 4g
  9. 4h
  10. 4t
  11. 4ab
  12. 4bc
  13. 4th
  14. 4abc
  15. 4bcd
  16. 1234
复制代码

[ 本帖最后由 ubuntun 于 2007-12-15 23:49 编辑 ]
作者: ocean390    时间: 2007-12-16 00:00
这个正则表达式匹配4或者4ab,所以只要这一行里含有4,egrep就会认为这一行是匹配的。
作者: cjaizss    时间: 2007-12-16 00:33
4(ab)?和4|4ab一个意思
作者: 小N哥哥    时间: 2007-12-17 10:16
?={0,1}
(ab)是一个String
作者: ubuntun    时间: 2007-12-17 10:50
多谢以上各位。
脑子糊涂了,不过现在已清醒。
结贴!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2