1

I often use grep to do searches like

    grep -nr "matchFound[[:space:]]*=[[:space:]]*true" . 

to look for something like

    matchFound = true
    matchFound   =   true

But just for the sake of space, the syntax is so verbose. Is it possible to make it less verbose?

Please note: I am using grep on Windows 7.

CodeBlue
  • 14,631
  • 33
  • 94
  • 132

1 Answers1

2
grep -nr "matchFound\s*=\s*true"
Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
  • Usually, `\s` is equivalent to `[ \t\r\n]` in regular expressions, to be more precise. Some other flavors are possible, though, but they should be exotic. – Alexander Pavlov Apr 10 '12 at 14:18
  • Wild guess: try double-escaping: `\\s`. On a similar note, this worked for me in cygwin: `$ echo "matchFound = true" | grep -nr "matchFound\s*=\s*true"` gave `1:matchFound = true`. – Alexander Pavlov Apr 10 '12 at 14:23
  • I'll try it on Cygwin and get back to you. – CodeBlue Apr 10 '12 at 14:34
  • Yes, this works on Cygwin. I am not sure how I can get this to work without Cygwin, but thanks for the answer . – CodeBlue Apr 10 '12 at 15:15
  • So, what kind of the `grep` utility are you using? – Alexander Pavlov Apr 10 '12 at 15:26
  • I had a setup file and some DLLs. I don't remember where I got it from. But with that I can use grep on Windows without having anything like Cygwin. But I suppose in such kinds of situations it fails. – CodeBlue Apr 10 '12 at 15:31
  • OK, have a look at [this SO question](http://stackoverflow.com/questions/87350/what-are-good-grep-tool-for-windows) - it has a fair amount of discussion about good Windows grep tools. – Alexander Pavlov Apr 10 '12 at 15:41
  • Thanks to you, now I am using mintty on Cygwin!! It's so much better than the usual Windows Command Prompt. – CodeBlue Apr 11 '12 at 13:17