Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to follow a section in The GNU Grep Manual but my expression isn't working. Is it my grep version? Red Hat 5.5.

$ rm file
$ echo 'hello world' > file
$ grep 'hello world' file
hello world
$ grep 'hello\sworld' file

Returns nothing. grep-2.5.1-55.el5

share|improve this question
Works with grep (GNU grep) 2.14 – Hauke Laging Feb 21 '14 at 0:02
Does grep 'hello[[:space:]]world' file work? – Ketan Feb 21 '14 at 0:13
[:space:] and [:blank:] work. But why doesn't \s work? – Felipe Alvarez Feb 21 '14 at 1:25
up vote 2 down vote accepted

The special handling of \s was added in grep 2.6.3. Commit message

Whenever possible, use the info docs that are on your system. Just run info grep.

To get this behavior, try adding the -P flag to make it work in Perl regex mode.

share|improve this answer
I knew it must be the version number. I'll need to make do with this for now. Thanks to all contributions. – Felipe Alvarez Feb 21 '14 at 2:40

I could reproduce your issue with GNU grep v2.5.1.

However, when I use -i switch it worked:

grep -i 'hello\sworld' file

From the man page:

-i, --ignore-case Ignore case distinctions in both the PATTERN and the input files.

It might be a bug in grep.

share|improve this answer
You are right. -i causes it to return the result I want. Curiously though, without -i, both \S and \s both fail to return expected results. – Felipe Alvarez Feb 21 '14 at 2:42

You should use "" instead of '' :

grep "hello\sworld" file

When you use '' grep discardes scape codes.

share|improve this answer
double quotes returns the same result (nothing) – Felipe Alvarez Feb 21 '14 at 1:24
This is not true, the string is exactly the same in both types of quotes in this instance. – Chris Down Feb 21 '14 at 2:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.