Why is grep missing missing matches when searching multiple directories?

0

Trying to grep the files in several child directories, grep returns nothing.

~/box/raw $ grep ":2259\"" f*/hh*.adt
~/box/raw $ 

But when I descend into one of the child directories, grep finds a match.

~/box/raw/f040 $ grep ":2259\"" hh*.adt
hh_sr2014_v8.adt:"2/23/2015 2:33:49 PM","Leave Field:Introduction.BQ1a","Cause:Next Field","Status:Normal","Value:2259"

This works (i.e., finds the match):

~/box/raw $ grep ":2259\"" f040/hh*.adt

But these don't:

~/box/raw $ grep ":2259\"" f???/hh*.adt
~/box/raw $ grep ":2259\"" f???/hh_sr2014_v8.adt
~/box/raw $ grep ":2259\"" f*/hh_sr2014_v8.adt

There seem to be some rules about wildcard expansion in directory names that I don't understand. What are they?

This is on Cygwin on a Windows 7 machine. uname -r gives me "1.7.33-2(0.280/5/3)".

katriel

Posted 2015-04-03T06:09:15.503

Reputation: 155

1can you try some testing with other commands e.g. ls, I think this may show that the issue is down to cygwin's shell expansion not grep. – gogoud – 2015-04-03T06:29:18.330

1+1 gogoud, ~/box $ ls r*/f* gives "no such file or directory", because ls and grep are case sensitive but the filesystem isn't. – katriel – 2015-04-03T06:47:38.970

Answers

0

Add the following to your ~/.bashrc file:

shopt -s nocaseglob

Then log out and back in to Cygwin (not Windows), now the bash shell will not be case sensitive any more when it is globbing filenames. More info here.

gogoud

Posted 2015-04-03T06:09:15.503

Reputation: 1 068

2“Then log out and back in to Cygwin…” Not too sure about Cygwin, but on most any Linux/Unix-based system one could simply type in the following command to reload a config: source ~/.bashrc – JakeGould – 2015-04-03T07:07:06.760