8

The complement of \s is \S, not [^\s] which (with the help of -i) excluded 'SIX' and 'Sam' from the result because they contain a literal s. How to grep -i for lines starting with "host", followed by one or more whitespaces and a sequence of one or more characters until the end of the line, where no literal * or whitespace can exist: grep -Ei '^...


6

Interpreting \s as whitespace is an extension of GNU Grep. It is not defined in POSIX. BSD Grep, for example, does not identify \s as whitespace. Perl regexes are also an extension to POSIX, but both BSD and GNU provide it. For a totally portable expression, you should use [[:space:]] instead. The GNU Grep manual states somewhat loosely that "most meta-...


2

The effect of a backslash in the regular expression part of [[ str =~ rex ]] is to quote the following character (exactly like putting it in single quotes), which would direct bash to do a literal match for it (1). Since b is not special, \b will turn into just b, but '\', "\\" or \\ will turn into \\ in order to match a literal backslash: [[ ...


1

When you say \w+, I assume you actually mean [a-zA-Z] since \w also matches numbers and underscores and it looks like you only want letters. In fact, based on your example, you might only want capital letters. Finally, and again I'm guessing here since you don't explain, it looks like you want to exclude cases where the letters string is not exactly 3 ...


Only top voted, non community-wiki answers of a minimum length are eligible