grep regex whitespace behavior

后端 未结 1 1100
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 10:53

I have a textfile, containing something like:

12,34 EUR 
 5,67 EUR
 ...

There is one whitespace before \'EUR\' and I ignore 0,XX EUR.

相关标签:
1条回答
  • 2020-12-02 11:43

    This looks like a behavior difference in the handling of \s between grep 2.5 and newer versions (a bug in old grep?). I confirm your result with grep 2.5.4, but all four of your greps do work when using grep 2.6.3 (Ubuntu 10.10).

    Note:

    GNU grep 2.5.4
    echo "foo bar" | grep "\s"
       (doesn't match)
    

    whereas

    GNU grep 2.6.3
    echo "foo bar" | grep "\s"
    foo bar
    

    Probably less trouble (as \s is not documented):

    Both GNU greps
    echo "foo bar" | grep "[[:space:]]"
    foo bar
    

    My advice is to avoid using \s ... use [ \t]* or [[:space:]] or something like it instead.

    0 讨论(0)
提交回复
热议问题