Questions tagged [findstr]

findstr is a Windows command that searches for patterns of text in one or more files using regular expressions.

Useful links:

  1. FINDSTR on technet.
  2. FINDSTR on SS64 help pages.
730 questions
209
votes
8 answers

What are the undocumented features and limitations of the Windows FINDSTR command?

The Windows FINDSTR command is horribly documented. There is very basic command line help available through FINDSTR /?, or HELP FINDSTR, but it is woefully inadequate. There is a wee bit more documentation online at…
dbenham
  • 127,446
  • 28
  • 251
  • 390
175
votes
8 answers

Regex - how to match everything except a particular pattern

How do I write a regex to match any string that doesn't meet a particular pattern? I'm faced with a situation where I have to match an (A and ~B) pattern.
notnot
  • 4,472
  • 12
  • 46
  • 57
42
votes
5 answers

Regular expressions in findstr

I'm doing a little string validation with findstr and its /r flag to allow for regular expressions. In particular I'd like to validate integers. The regex ^[0-9][0-9]*$ worked fine for non-negative numbers but since I now support negative numbers…
Joey
  • 344,408
  • 85
  • 689
  • 683
39
votes
4 answers

How to write a search pattern to include a space in findstr?

I want to search all files in a certain directory for occurrences of statements such as Load frmXYZ I am on Windows 7, using the findstr command. I tried: findstr /n Load.*frm *.* But this gives me unwanted results such as: If ABCFormLoaded…
CodeBlue
  • 14,631
  • 33
  • 94
  • 132
20
votes
1 answer

Piping to findstr's input

I have a text file with a list of macro names (one per line). My final goal is to get a print of how many times the macro's name appears in the files of the current directory. The macro's names are in C:\temp\macros.txt. type C:\temp\macros.txt in…
Gauthier
  • 40,309
  • 11
  • 63
  • 97
20
votes
2 answers

Windows 'findstr' command: Exclude results containing particular string

To the command findstr str1 *.* I want to add something that will exclude the results which contain the string str2. In Linux the way of doing it is to add | grep -v str2 (to grep str1 * of course). Is there an equivalent flag to -v in Windows?
Subway
  • 5,286
  • 11
  • 48
  • 59
19
votes
2 answers

Searching recursively one string on windows OS

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…
someone
  • 1,638
  • 3
  • 21
  • 36
18
votes
4 answers

Why does findstr not handle case properly (in some circumstances)?

While writing some recent scripts in cmd.exe, I had a need to use findstr with regular expressions - customer required standard cmd.exe commands (no GnuWin32 nor Cygwin nor VBS nor Powershell). I just wanted to know if a variable contained any…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
14
votes
2 answers

findstr exit codes/errorlevel

I have a program that is using findstr, and when the string is found the errorlevel returns 0 and when the string is not found the errorlevel returns 1. Alright, that's fine I can deal with that. Where the issue lies is I cannot find any official…
Saltz3
  • 324
  • 1
  • 4
  • 15
13
votes
7 answers

findstr or grep that autodetects chararacter encoding (UTF-16)

I want to do this: findstr /s /c:some-symbol * or the grep equivalent grep -R some-symbol * but I need the utility to autodetect files encoded in UTF-16 (and friends) and search them appropriately. My files even have the byte-ordering mark…
David Martin
  • 181
  • 1
  • 2
  • 7
11
votes
2 answers

Why doesn't this FINDSTR example with multiple literal search strings find a match?

Sometimes FINDSTR with multiple literal search strings fails to find all matches. For example, the following FINDSTR example fails to find a match. echo ffffaaa|findstr /l "ffffaaa faffaffddd" Why?
dbenham
  • 127,446
  • 28
  • 251
  • 390
11
votes
4 answers

Escaping a quote in findstr search string

How can I properly escape a quote in a search string when using findstr.exe? Example: findstr /misc:"namespace=\"" *.cs > ns.txt This outputs to the console, instead of to the file I specified. I am doing this directly on the command line, not…
Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183
11
votes
3 answers

Findstr - Return only a regex match

I have this string in a text file (test.txt): BLA BLA BLA BLA BLA Found 11 errors and 7 warnings I perform this command: findstr /r "[0-9]+ errors" test.txt In order to get just 11 errors string. Instead, the output is: Found 11 errors and 7…
ohadinho
  • 6,894
  • 16
  • 71
  • 124
11
votes
3 answers

Batch program find string in variable

I tried to find the solutions in many places but couldn't find specific answer. I am creating a batch script. The following is my code so far @echo off SETLOCAL EnableDelayedExpansion cls for /f "delims=" %%a in ('rasdial EVDO cdma…
Sid1024
  • 159
  • 1
  • 1
  • 7
10
votes
2 answers

findstr ms-dos command won't search sub directories

I had to switch off my windows search indexing in Windows 7 as the old hard disk was constantly making noise with indexing switched on! Now I want to use Windows command prompt to search for a specific text term within all files located within the…
DeadlyDan
  • 669
  • 2
  • 8
  • 20
1
2 3
48 49