2

I'm trying to use grep on Windows to search all files in the current directory for the word foo followed by any white space.

I tried:

grep foo\s *

But it doesn't work. It matches foos though. I was under the impression that \s should match a white space. Indeed it does in other regular expression testers.

I also tried grep foo\\s * grep "foo\s" * and countless other attempts.

What am I missing?

I'm using GNU grep 2.5.4 on Windows 10 in cmd.exe

Wyck
  • 10,311
  • 6
  • 39
  • 60

1 Answers1

1

It seems there is a bug with the handling of \s in grep up to version 2.5 grep regex whitespace behavior

You have several alternatives to it

grep "foo[ \t] *
grep "foo[[:space:]]" *

or if you dont care about tabulation

grep "foo " *
Alain Merigot
  • 10,667
  • 3
  • 18
  • 31
  • Is there a version of grep later than 2.5.4 with a fix? Web search unfortunately directs me to [2.5.4](http://gnuwin32.sourceforge.net/packages/grep.htm) which I already have. – Wyck May 24 '19 at 19:28
  • On my computer (ubuntu 18), this is grep 3.1. Probably you can find this version for win. – Alain Merigot May 24 '19 at 19:30