I have a file called test.txtwith contents like below:
Si 28.086 Si.bhs
As 74.90000 As.pz-bhs.UPF
Here is some of my running of grep
I just can't understand, why grep bhs[^\.] test.txt won't grep the first line? Could someone please explain? Doesn't [^\.] represent any character other than dot?

echo \.andecho [^\.]. Quote your regexes. – muru Mar 06 '17 at 02:18bhson the first line? "followed by not dot" is not the same as "not followed by dot" – steeldriver Mar 06 '17 at 02:21grep bhs[^\\.] test.txtnorgrep 'bhs[^\\.] ' test.txtworks – user15964 Mar 06 '17 at 02:26grep 'bhs$'or (if yourgrepsupports PCRE mode) usegrep -P 'bhs(?!\.)'– steeldriver Mar 06 '17 at 02:26bhs[^\.]matches the first bhs – user15964 Mar 06 '17 at 02:28grep -P 'bhs[^\\.]' test.txtdoesn't work – user15964 Mar 06 '17 at 02:30grepsearches within lines. The newline character (\n) is the terminator of the line, so[^.]won't match it. Note that[^\.]is actually "any character except backslash or dot", as characters are not considered special within character classes – Fox Mar 06 '17 at 02:33[^\.]also contains backslash? Isn't\.the escaping of dot? – user15964 Mar 06 '17 at 02:37printf 'bhs\\xyz\n' | grep 'bhs[^\.]'. If your regexp is left unquoted, then your shell eats the backslash beforegrepgets it – Fox Mar 06 '17 at 02:40grepandgrep -Ptreat[^\.]differently – user15964 Mar 06 '17 at 02:59grep 'bhs\.'andgrep 'bhs[^.]'– muru Mar 06 '17 at 05:27