문제

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