سؤال

I want to search one string e.g. "main" in my project on windows OS recursively. I searched that and find a solution Windows recursive grep command-line

I applied same with two different approach, and result is not as expected.

e.g. my approach

findstr /S "main" *.cpp

but when I choose

findstr /S "int main" *.cpp

I am not getting only my main function. What is the difference between these two approaches? is it wrong to provide strings with space?

هل كانت مفيدة؟

المحلول

This is because findstr takes a set of strings to search for. To actually match the string int main you have to use the /C option:

findstr /s /C:"int main" *.cpp

whereas your variant gives you every line with either int or main.

نصائح أخرى

Kind of late to the party here, but if you use

findstr /S "int.main" *.cpp

it will treat the dot as a wild card, which matches a space, and as long as you don't mind some superfluous matches (which are unlikely in this case) it will work fine for you.

I use that, having not known about the /C: option before reading the answers above.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top