学习《鳥哥的私房菜》中的内容,学到命令 grep 时,遇到怪事如下:
先编辑oo.txt
"Open Source" is a good mechanism to develop programs.
apple is my favorite food.
Football game is not use feet only.
The soup taste good.
I cant't finish the test.
google is the best tools for serch keyword.
goooooogle yes!
$ grep -n '[^fgot]oo' oo.txt
3:Football game is not use feet only.
$ grep -n '[^a-z]oo' oo.txt
应该也给出上述命令的标准输出。但是我的屏幕没有任何输出。这是怎么回事?
学习grep 遇到的怪事
-
- 帖子: 345
- 注册时间: 2007-10-22 16:54
-
- 帖子: 345
- 注册时间: 2007-10-22 16:54
Re: 学习grep 遇到的怪事
再试如下:
yuanbx@hp:~$ grep -n '[^g-z]oo' oo.txt
2:apple is my favorite food.
3:Football game is not use feet only.
yuanbx@hp:~$ grep -n '[^f-z]oo' oo.txt
yuanbx@hp
yuanbx@hp:~$ grep -n '[^g-z]oo' oo.txt
2:apple is my favorite food.
3:Football game is not use feet only.
yuanbx@hp:~$ grep -n '[^f-z]oo' oo.txt
yuanbx@hp
-
- 帖子: 345
- 注册时间: 2007-10-22 16:54
Re: 学习grep 遇到的怪事
今天我用以前的光盘启动了一下电脑,使用了一下ubuntu9.10, grep 的功能很正常。不知是ubuntu10.10 的毛病,还是
grep 2.6.3 的臭虫。ubuntu 9.10下的grep 是2.5.10.
grep 2.6.3 的臭虫。ubuntu 9.10下的grep 是2.5.10.
-
- 帖子: 345
- 注册时间: 2007-10-22 16:54
Re: 学习grep 遇到的怪事
我下载装上了grep 2.7, 试後没有了上述问题。如果你的系统也是ubuntu10.10. 试一试与我见到的情况是不是一样。
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
-
- 帖子: 61
- 注册时间: 2010-04-29 22:00
- 系统: Gentoo Linux ~amd64
- 联系:
- sunsol
- 帖子: 55
- 注册时间: 2009-01-04 21:55
Re: 学习grep 遇到的怪事
gnu grep对[a-z]有的时候会有问题,特别是中文环境
主要是因为其考虑到非英文字符
跟环境设置有关,把LANG设成en_US试试看
windows下记得好像是把LC_ALL设成C
主要是因为其考虑到非英文字符
跟环境设置有关,把LANG设成en_US试试看
windows下记得好像是把LC_ALL设成C
-
- 帖子: 186
- 注册时间: 2010-05-25 16:49
Re: 学习grep 遇到的怪事
楼上正解sunsol 写了:gnu grep对[a-z]有的时候会有问题,特别是中文环境
主要是因为其考虑到非英文字符
跟环境设置有关,把LANG设成en_US试试看
windows下记得好像是把LC_ALL设成C
设成 LANG=C
或者使用[^[:lower:]]代替[^a-z]
上次由 only_one 在 2011-03-05 21:11,总共编辑 1 次。
-
- 帖子: 186
- 注册时间: 2010-05-25 16:49
Re: 学习grep 遇到的怪事
这个问题鸟哥有说过哦