我有一个文本文件,包含如下内容:
12,34 EUR 
 5,67 EUR
 ...
在'EUR'之前有一个空格,我忽略0,XX EUR.
我试过了:
grep '[1-9][0-9]*,[0-9]\{2\}\sEUR' => didn't match !
grep '[1-9][0-9]*,[0-9]\{2\} EUR' => worked !
grep '[1-9][0-9]*,[0-9]\{2\}\s*EUR' => worked !
grep '[1-9][0-9]*,[0-9]\{2\}\s[E]UR'  => worked !
有人可以解释我请,我为什么不能用\s,但\s*和\s[E]匹配?
操作系统:Ubuntu 10.04,grep v2.5
Kam*_*mal 103
这看起来像处理\sgrep 2.5和更新版本之间的行为差异(旧grep中的错误?).我使用grep 2.5.4确认你的结果,但是当使用grep 2.6.3(Ubuntu 10.10)时,你的所有四个greps都能正常工作.
注意:
GNU grep 2.5.4
echo "foo bar" | grep "\s"
   (doesn't match)
而
GNU grep 2.6.3
echo "foo bar" | grep "\s"
foo bar
可能不那么麻烦(\s没有记录):
Both GNU greps
echo "foo bar" | grep "[[:space:]]"
foo bar
我的建议是避免使用\s...使用[ \t]*或[[:space:]]或类似的东西来代替.