When converting a regexp from a sed script into a grep basic regexp, I kept some of the \s subexpressions (\s matches any whitespace character in sed regexps). After reading the man page, I realised that the meaning of the expression '\s' is undefined in grep. However, inserting the string \s in a grep pattern gives really confusing results, it does not even seem to be a regular expression: Sometimes \s seems to match whitespace, sometimes it does not. Example:
(1)$ echo 'a b' |grep -G -e '^a\(\s\+\)b' - no match (2)$ echo 'a b' |grep -G -e '^a\(\s\+\)\?b' - match (3)$ echo 'a b' |grep -G -e '^ab' - no match (4)$ echo 'a b' |grep -G -e '^a\(x\s\+\)\?b' - no match If \s is a regular expression, then I don't understand how (2) matches while (1) and (4) don't. Am I missing something? $ grep --version GNU grep 2.5.3 greetings, Erik