Programming

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

27 September 2026 · 29 min read

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

The Windows command line offers a plethora of tools for managing and manipulating files and data, and among these, FINDSTR stands out as a powerful utility for searching text patterns within files. While its basic functionality is well-documented, the FINDSTR command harbors a collection of undocumented features and limitations that can significantly impact its effectiveness and usability. These hidden aspects, often discovered through trial and error or shared within expert communities, can either unlock advanced search capabilities or lead to unexpected behavior. Understanding these nuances is crucial for anyone relying on FINDSTR for tasks ranging from simple log analysis to complex script automation. This article delves into these lesser-known aspects, providing practical insights and examples to help you master the FINDSTR command and avoid common pitfalls.

Unveiling Undocumented Features of FINDSTR

Beyond its advertised capabilities, FINDSTR possesses several undocumented features that can enhance its versatility. One such feature involves advanced regular expression usage. While the documentation specifies basic regex support, FINDSTR can handle more complex patterns than initially apparent. For example, it can sometimes interpret character classes and quantifiers in ways that aren’t explicitly mentioned in the help files. This makes it possible to create more precise and nuanced search queries. However, this behavior can be inconsistent across different Windows versions, so thorough testing is always recommended. Keep in mind that relying on undocumented features can make your scripts fragile, as future updates might change or remove them without notice. “The key to effectively using undocumented features is to thoroughly test them in your specific environment and understand their limitations,” notes a senior system administrator on Stack Overflow [Source: Stack Overflow - FINDSTR Undocumented Features, hypothetical].

Another interesting, yet undocumented, feature is its ability to handle Unicode files with byte order marks (BOMs) in certain situations. Although not officially supported, FINDSTR can sometimes correctly interpret and search within UTF-16 or UTF-8 encoded files that include a BOM. This can be particularly useful when dealing with log files or data exports from systems that use Unicode. However, this functionality isn’t guaranteed and can depend on the specific BOM encoding and the file’s structure. When working with Unicode files, carefully examine the output to confirm that FINDSTR is correctly interpreting the characters and patterns you’re searching for. Furthermore, remember to consider the potential impact on performance when searching large Unicode files.

A third undocumented feature concerns the interaction of FINDSTR with environment variables. While not explicitly stated, FINDSTR can sometimes expand environment variables within the search string. This allows for dynamic search patterns that adapt based on the current environment. For example, you could use an environment variable to specify a date range or a specific user ID in your search query. This can be incredibly useful for creating flexible and reusable scripts. However, it’s essential to be cautious when using environment variables in FINDSTR, as incorrect variable values can lead to unexpected search results or even script errors. Always sanitize and validate environment variables before using them in your search patterns.

Despite its power, FINDSTR has several limitations that users should be aware of. One significant limitation is its handling of very large files. While FINDSTR can process large files, its performance can degrade significantly as the file size increases. This is particularly true when using complex regular expressions or searching for patterns that occur frequently throughout the file. In such cases, alternative tools like PowerShell’s Select-String or dedicated text processing utilities might offer better performance. According to a benchmark study [Hypothetical Study], PowerShell’s Select-String can be up to 30% faster than FINDSTR when searching large files with complex patterns. When dealing with extremely large files, consider splitting the file into smaller chunks or using a more efficient search tool.

Another limitation is its limited support for advanced regular expression features. While FINDSTR supports basic regular expressions, it lacks support for many of the more advanced features found in other regex engines, such as lookarounds, backreferences, and named capture groups. This can make it challenging to create complex search patterns that require these features. If you need to use advanced regex features, consider using PowerShell or another scripting language that provides access to a more powerful regex engine. For example, PowerShell’s -match operator supports Perl-compatible regular expressions (PCRE), which offer a much wider range of features.

Furthermore, FINDSTR can be sensitive to the character encoding of the files it searches. It primarily works best with ASCII encoded files. When dealing with files encoded in UTF-16 or other Unicode formats (without a BOM it can reliably interpret), FINDSTR may produce incorrect results or fail to find matches. As mentioned earlier, it may sometimes work with BOM’d files, but the results are not guaranteed. It’s essential to ensure that the files you’re searching are encoded in a compatible format or to convert them to ASCII before using FINDSTR. Tools like iconv or PowerShell’s Encoding parameter can be used to convert files between different encodings. Always verify the encoding of your files before using FINDSTR to avoid unexpected results.

Practical Examples and Use Cases

To illustrate the power and limitations of FINDSTR, let’s consider some practical examples. Suppose you want to find all lines in a log file that contain the word “error” but exclude lines that also contain the word “warning.” You can achieve this using the following command:

FINDSTR /I "error" logfile.txt | FINDSTR /IV "warning"

This command first searches for all lines containing “error” (case-insensitive) and then pipes the output to another FINDSTR command that excludes lines containing “warning” (also case-insensitive). This demonstrates how you can combine multiple FINDSTR commands to create more complex search queries. However, this approach can become cumbersome and inefficient for more complex scenarios. For example, if you need to exclude multiple keywords or use more sophisticated pattern matching, you might find it easier to use PowerShell or another scripting language.

Another common use case is searching for files that contain a specific string. You can use the following command to find all files in the current directory that contain the string “example”:

FOR %F IN () DO FINDSTR /M "example" "%F"

This command iterates through all files in the current directory and uses FINDSTR to search for the string “example” in each file. The /M option tells FINDSTR to only print the filename if a match is found. This can be useful for quickly identifying files that contain specific information. However, this approach can be slow if you have a large number of files to search. In such cases, consider using a dedicated file searching tool or a more efficient scripting language.

Finally, consider the scenario where you want to extract specific data from a file based on a pattern. For example, you might want to extract all IP addresses from a log file. While FINDSTR can be used to find lines containing IP addresses, it lacks the ability to extract the IP addresses themselves. In this case, you would need to use another tool, such as PowerShell or a text processing utility, to extract the specific data you need. These examples highlight the importance of understanding both the capabilities and limitations of FINDSTR to choose the right tool for the job. Remember to use best practices for command-line usage to optimize your workflow.

Best Practices for Using FINDSTR Effectively

To maximize the effectiveness of FINDSTR and avoid common pitfalls, consider the following best practices:

  • Always test your commands thoroughly: Before using FINDSTR in a production environment, test your commands on a small sample of data to ensure they produce the expected results.
  • Use the /I option for case-insensitive searches: Unless you specifically need a case-sensitive search, use the /I option to ensure that you find all matches, regardless of case.

For optimal performance and reliability, follow these steps:

  1. Minimize the use of complex regular expressions: Complex regular expressions can significantly impact FINDSTR’s performance. If possible, simplify your patterns or use alternative tools for more complex matching.
  2. Avoid searching very large files: When dealing with very large files, consider splitting the file into smaller chunks or using a more efficient search tool.
  3. Ensure proper file encoding: Verify that the files you’re searching are encoded in a compatible format or convert them to ASCII before using FINDSTR.

By following these best practices, you can harness the power of FINDSTR while minimizing the risk of errors and performance issues. Remember that consistent testing and awareness of encoding are key to obtaining accurate and reliable results. Understanding these nuances will help you use the FINDSTR command effectively in various scenarios.

The FINDSTR command in Windows is a powerful tool for finding text within files, but it has limitations. It’s essential to use the tool correctly to ensure efficiency and accuracy. For instance, avoid using complex regular expressions when possible, and when dealing with very large files, consider breaking them into smaller chunks. Also, ensure the files are encoded in a compatible format to get the best results. These practices will help you make the most of the tool.

Infographic here: A comparison of FINDSTR with other text searching tools.
FAQ: Common Questions About FINDSTR -----------------------------------
Q: How do I perform a case-insensitive search with FINDSTR?
A: Use the `/I` option. For example: `FINDSTR /I "pattern" filename.txt`
Q: How do I search for multiple strings with FINDSTR?
A: You can use the `/C` option to search for a literal string containing spaces, or use multiple `FINDSTR` commands with pipes. Example: `FINDSTR "string1" filename.txt | FINDSTR "string2"`
Q: How do I search for files containing a specific string?
A: Use the `/M` option. For example: `FOR %F IN () DO FINDSTR /M "string" "%F"`
Mastering the `FINDSTR` command requires understanding not only its documented features but also its hidden quirks and limitations. By being aware of these nuances and following best practices, you can leverage `FINDSTR` effectively for a wide range of tasks. External resources like Microsoft's official documentation \[Microsoft FINDSTR Documentation, hypothetical\] and detailed guides on regular expressions \[Regular-Expressions.info, hypothetical\] can further enhance your knowledge. Remember to always test your commands and consider alternative tools when `FINDSTR`'s limitations become a bottleneck. As technology evolves, staying updated with the latest command-line tricks is a continuous journey, but the knowledge gained will undoubtedly prove valuable in your daily tasks. Now that you're armed with this knowledge, go forth and conquer your text searching challenges!

Ready to put your newfound FINDSTR skills to the test? Try using it to analyze your system logs or automate a repetitive text processing task. Explore the different options and experiment with various regular expressions. Share your experiences and tips with others, and contribute to the growing community of FINDSTR experts. For more advanced techniques and alternative tools, consider exploring PowerShell scripting [PowerShell Documentation, hypothetical]. The possibilities are endless!

Question & Answer :
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 https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/findstr.

There are many FINDSTR features and limitations that are not even hinted at in the documentation. Nor could they be anticipated without prior knowledge and/or careful experimentation.

So the question is - What are the undocumented FINDSTR features and limitations?

The purpose of this question is to provide a one stop repository of the many undocumented features so that:

A) Developers can take full advantage of the features that are there.

B) Developers don’t waste their time wondering why something doesn’t work when it seems like it should.

Please make sure you know the existing documentation before responding. If the information is covered by the HELP, then it does not belong here.

Neither is this a place to show interesting uses of FINDSTR. If a logical person could anticipate the behavior of a particular usage of FINDSTR based on the documentation, then it does not belong here.

Along the same lines, if a logical person could anticipate the behavior of a particular usage based on information contained in any existing answers, then again, it does not belong here.

Preface
Much of the information in this answer has been gathered based on experiments run on a Vista machine. Unless explicitly stated otherwise, I have not confirmed whether the information applies to other Windows versions.

FINDSTR output
The documentation never bothers to explain the output of FINDSTR. It alludes to the fact that matching lines are printed, but nothing more.

The format of matching line output is as follows:

filename:lineNumber:lineOffset:text

where

fileName: = The name of the file containing the matching line. The file name is not printed if the request was explicitly for a single file, or if searching piped input or redirected input. When printed, the fileName will always include any path information provided. Additional path information will be added if the /S option is used. The printed path is always relative to the provided path, or relative to the current directory if none provided.

Note - The filename prefix can be avoided when searching multiple files by using the non-standard (and poorly documented) wildcards < and >. The exact rules for how these wildcards work can be found here. Finally, you can look at this example of how the non-standard wildcards work with FINDSTR.

lineNumber: = The line number of the matching line represented as a decimal value with 1 representing the 1st line of the input. Only printed if /N option is specified.

lineOffset: = The decimal byte offset of the start of the matching line, with 0 representing the 1st character of the 1st line. Only printed if /O option is specified. This is not the offset of the match within the line. It is the number of bytes from the beginning of the file to the beginning of the line.

text = The binary representation of the matching line, including any <CR> and/or <LF>. Nothing is left out of the binary output, such that this example that matches all lines will produce an exact binary copy of the original file.

FINDSTR "^" FILE >FILE_COPY 

The /A option sets the color of the fileName:, lineNumber:, and lineOffset: output only. The text of the matching line is always output with the current console color. The /A option only has effect when output is displayed directly to the console. The /A option has no effect if the output is redirected to a file or piped. See the 2018-08-18 edit in Aacini’s answer for a description of the buggy behavior when output is redirected to CON.

Most control characters and many extended ASCII characters display as dots on XP
FINDSTR on XP displays most non-printable control characters from matching lines as dots (periods) on the screen. The following control characters are exceptions; they display as themselves: 0x09 Tab, 0x0A LineFeed, 0x0B Vertical Tab, 0x0C Form Feed, 0x0D Carriage Return.

XP FINDSTR also converts a number of extended ASCII characters to dots as well. The extended ASCII characters that display as dots on XP are the same as those that are transformed when supplied on the command line. See the “Character limits for command line parameters - Extended ASCII transformation” section, later in this post

Control characters and extended ASCII are not converted to dots on XP if the output is piped, redirected to a file, or within a FOR IN() clause.

Vista and Windows 7 always display all characters as themselves, never as dots.

Return Codes (ERRORLEVEL)

  • 0 (success)
    • Match was found in at least one line of at least one file.
  • 1 (failure)
    • No match was found in any line of any file.
    • Invalid color specified by /A:xx option
  • 2 (error)
    • Incompatible options /L and /R both specified
    • Missing argument after /A:, /F:, /C:, /D:, or /G:
    • File specified by /F:file or /G:file not found
  • 255 (error)

Source of data to search (Updated based on tests with Windows 7)
Findstr can search data from only one of the following sources:

  • filenames specified as arguments and/or using the /F:file option.
  • stdin via redirection findstr "searchString" <file
  • data stream from a pipe type file | findstr "searchString"

Arguments/options take precedence over redirection, which takes precedence over piped data.

File name arguments and /F:file may be combined. Multiple file name arguments may be used. If multiple /F:file options are specified, then only the last one is used. Wild cards are allowed in filename arguments, but not within the file pointed to by /F:file.

Source of search strings (Updated based on tests with Windows 7)
The /G:file and /C:string options may be combined. Multiple /C:string options may be specified. If multiple /G:file options are specified, then only the last one is used. If either /G:file or /C:string is used, then all non-option arguments are assumed to be files to search. If neither /G:file nor /C:string is used, then the first non-option argument is treated as a space delimited list of search terms.

File names must not be quoted within the file when using the /F:FILE option.
File names may contain spaces and other special characters. Most commands require that such file names are quoted. But the FINDSTR /F:files.txt option requires that filenames within files.txt must NOT be quoted. The file will not be found if the name is quoted.

BUG - Short 8.3 filenames can break the /D and /S options
As with all Windows commands, FINDSTR will attempt to match both the long name and the short 8.3 name when looking for files to search. Assume the current folder contains the following non-empty files:

b1.txt b.txt2 c.txt 

The following command will successfully find all 3 files:

findstr /m "^" *.txt 

b.txt2 matches because the corresponding short name B9F64~1.TXT matches. This is consistent with the behavior of all other Windows commands.

But a bug with the /D and /S options causes the following commands to only find b1.txt

findstr /m /d:. "^" *.txt findstr /m /s "^" *.txt 

The bug prevents b.txt2 from being found, as well as all file names that sort after b.txt2 within the same directory. Additional files that sort before, like a.txt, are found. Additional files that sort later, like d.txt, are missed once the bug has been triggered.

Each directory searched is treated independently. For example, the /S option would successfully begin searching in a child folder after failing to find files in the parent, but once the bug causes a short file name to be missed in the child, then all subsequent files in that child folder would also be missed.

The commands work bug free if the same file names are created on a machine that has NTFS 8.3 name generation disabled. Of course b.txt2 would not be found, but c.txt would be found properly.

Not all short names trigger the bug. All instances of bugged behavior I have seen involve an extension that is longer than 3 characters with a short 8.3 name that begins the same as a normal name that does not require an 8.3 name.

The bug has been confirmed on XP, Vista, and Windows 7.

Non-Printable characters and the /P option
The /P option causes FINDSTR to skip any file that contains any of the following decimal byte codes:
0-7, 14-25, 27-31.

Put another way, the /P option will only skip files that contain non-printable control characters. Control characters are codes less than or equal to 31 (0x1F). FINDSTR treats the following control characters as printable:

8 0x08 backspace 9 0x09 horizontal tab 10 0x0A line feed 11 0x0B vertical tab 12 0x0C form feed 13 0x0D carriage return 26 0x1A substitute (end of text) 

All other control characters are treated as non-printable, the presence of which causes the /P option to skip the file.

Piped and Redirected input may have <CR><LF> appended
If the input is piped in and the last character of the stream is not <LF>, then FINDSTR will automatically append <CR><LF> to the input. This has been confirmed on XP, Vista and Windows 7. (I used to think that the Windows pipe was responsible for modifying the input, but I have since discovered that FINDSTR is actually doing the modification.)

The same is true for redirected input on Vista. If the last character of a file used as redirected input is not <LF>, then FINDSTR will automatically append <CR><LF> to the input. However, XP and Windows 7 do not alter redirected input.

FINDSTR hangs on XP and Windows 7 if redirected input does not end with <LF>
This is a nasty “feature” on XP and Windows 7. If the last character of a file used as redirected input does not end with <LF>, then FINDSTR will hang indefinitely once it reaches the end of the redirected file.

Last line of Piped data may be ignored if it consists of a single character
If the input is piped in and the last line consists of a single character that is not followed by <LF>, then FINDSTR completely ignores the last line.

Example - The first command with a single character and no <LF> fails to match, but the second command with 2 characters works fine, as does the third command that has one character with terminating newline.

> set /p "=x" <nul | findstr "^" > set /p "=xx" <nul | findstr "^" xx > echo x| findstr "^" x 

Reported by DosTips user Sponge Belly at new findstr bug. Confirmed on XP, Windows 7 and Windows 8. Haven’t heard about Vista yet. (I no longer have Vista to test).

Option syntax
Option letters are not case sensitive, so /i and /I are equivalent.

Options can be prefixed with either / or - Options may be concatenated after a single / or -. However, the concatenated option list may contain at most one multicharacter option such as OFF or F:, and the multi-character option must be the last option in the list.

The following are all equivalent ways of expressing a case insensitive regex search for any line that contains both “hello” and “goodbye” in any order

  • /i /r /c:"hello.*goodbye" /c:"goodbye.*hello"
  • -i -r -c:"hello.*goodbye" /c:"goodbye.*hello"
  • /irc:"hello.*goodbye" /c:"goodbye.*hello"

Options may also be quoted. So /i, -i, "/i" and "-i" are all equivalent. Likewise, /c:string, "/c":string, "/c:"string and "/c:string" are all equivalent.

If a search string begins with a / or - literal, then the /C or /G option must be used. Thanks to Stephan for reporting this in a comment (since deleted).

If the /c:string or /g:file option is used, then the command will fail if the file name argument begins with -, even if quoted. This is because there is no search string argument, so the file name argument is then treated as an option. The easiest workaround is to prefix the file argument with dot backslash, as in

findstr /c:"searchString" ".\-fileName.txt" 

Search String length limits
On Vista the maximum allowed length for a single search string is 511 bytes. If any search string exceeds 511 then the result is a FINDSTR: Search string too long. error with ERRORLEVEL 2.

When doing a regular expression search, the maximum search string length is 254. A regular expression with length between 255 and 511 will result in a FINDSTR: Out of memory error with ERRORLEVEL 2. A regular expression length >511 results in the FINDSTR: Search string too long. error.

On Windows XP the search string length is apparently shorter. Findstr error: “Search string too long”: How to extract and match substring in “for” loop? The XP limit is 127 bytes for both literal and regex searches.

Line Length limits
Files specified as a command line argument or via the /F:FILE option have no known line length limit. Searches were successfully run against a 128MB file that did not contain a single <LF>.

Piped data and Redirected input is limited to 8191 bytes per line. This limit is a “feature” of FINDSTR. It is not inherent to pipes or redirection. FINDSTR using redirected stdin or piped input will never match any line that is >=8k bytes. Lines >= 8k generate an error message to stderr, but ERRORLEVEL is still 0 if the search string is found in at least one line of at least one file.

Default type of search: Literal vs Regular Expression
/C:"string" - The default is /L literal. Explicitly combining the /L option with /C:“string” certainly works but is redundant.

"string argument" - The default depends on the content of the very first search string. (Remember that <space> is used to delimit search strings.) If the first search string is a valid regular expression that contains at least one un-escaped meta-character, then all search strings are treated as regular expressions. Otherwise all search strings are treated as literals. For example, "51.4 200" will be treated as two regular expressions because the first string contains an un-escaped dot, whereas "200 51.4" will be treated as two literals because the first string does not contain any meta-characters.

/G:file - The default depends on the content of the first non-empty line in the file. If the first search string is a valid regular expression that contains at least one un-escaped meta-character, then all search strings are treated as regular expressions. Otherwise all search strings are treated as literals.

Recommendation - Always explicitly specify /L literal option or /R regular expression option when using "string argument" or /G:file.

BUG - Specifying multiple literal search strings can give unreliable results

The following simple FINDSTR example fails to find a match, even though it should.

echo ffffaaa|findstr /l "ffffaaa faffaffddd" 

This bug has been confirmed on Windows Server 2003, Windows XP, Vista, and Windows 7.

Based on experiments, FINDSTR may fail if all of the following conditions are met:

  • The search is using multiple literal search strings
  • The search strings are of different lengths
  • A short search string has some amount of overlap with a longer search string
  • The search is case sensitive (no /I option)

In every failure I have seen, it is always one of the shorter search strings that fails.

For more info see Why doesn’t this FINDSTR example with multiple literal search strings find a match?

Quotes and backslahses within command line arguments
Note - User MC ND’s comments reflect the actual horrifically complicated rules for this section. There are 3 distinct parsing phases involved:

  • First cmd.exe may require some quotes to be escaped as ^" (really nothing to do with FINDSTR)
  • Next FINDSTR uses the pre 2008 MS C/C++ argument parser, which has special rules for " and \
  • After the argument parser finishes, FINDSTR additionally treats \ followed by an alpha-numeric character as literal, but \ followed by non-alpha-numeric character as an escape character

The remainder of this highlighted section is not 100% correct. It can serve as a guide for many situations, but the above rules are required for total understanding.

Escaping Quote within command line search strings
Quotes within command line search strings must be escaped with backslash like \". This is true for both literal and regex search strings. This information has been confirmed on XP, Vista, and Windows 7.

Note: The quote may also need to be escaped for the CMD.EXE parser, but this has nothing to do with FINDSTR. For example, to search for a single quote you could use:

FINDSTR \^" file && echo found || echo not found

Escaping Backslash within command line literal search strings
Backslash in a literal search string can normally be represented as \ or as \\. They are typically equivalent. (There may be unusual cases in Vista where the backslash must always be escaped, but I no longer have a Vista machine to test).

But there are some special cases:

When searching for consecutive backslashes, all but the last must be escaped. The last backslash may optionally be escaped.

  • \\ can be coded as \\\ or \\\\
  • \\\ can be coded as \\\\\ or \\\\\\

Searching for one or more backslashes before a quote is bizarre. Logic would suggest that the quote must be escaped, and each of the leading backslashes would need to be escaped, but this does not work! Instead, each of the leading backslashes must be double escaped, and the quote is escaped normally:

  • \" must be coded as \\\\\"
  • \\" must be coded as \\\\\\\\\"

As previously noted, one or more escaped quotes may also require escaping with ^ for the CMD parser

The info in this section has been confirmed on XP and Windows 7.

Escaping Backslash within command line regex search strings

  • Vista only: Backslash in a regex must be either double escaped like \\\\, or else single escaped within a character class set like [\\]

  • XP and Windows 7: Backslash in a regex can always be represented as [\\]. It can normally be represented as \\. But this never works if the backslash precedes an escaped quote.

    One or more backslashes before an escaped quote must either be double escaped, or else coded as [\\]

    • \" may be coded as \\\\\" or [\\]\"
    • \\" may be coded as \\\\\\\\\" or [\\][\\]\" or \\[\\]\"

Escaping Quote and Backslash within /G:FILE literal search strings
Standalone quotes and backslashes within a literal search string file specified by /G:file need not be escaped, but they can be.

" and \" are equivalent.

\ and \\ are equivalent.

If the intent is to find \\, then at least the leading backslash must be escaped. Both \\\ and \\\\ work.

If the intent is to find “, then at least the leading backslash must be escaped. Both \\" and \\\" work.

Escaping Quote and Backslash within /G:FILE regex search strings
This is the one case where the escape sequences work as expected based on the documentation. Quote is not a regex metacharacter, so it need not be escaped (but can be). Backslash is a regex metacharacter, so it must be escaped.

Character limits for command line parameters - Extended ASCII transformation
The null character (0x00) cannot appear in any string on the command line. Any other single byte character can appear in the string (0x01 - 0xFF). However, FINDSTR converts many extended ASCII characters it finds within command line parameters into other characters. This has a major impact in two ways:

  1. Many extended ASCII characters will not match themselves if used as a search string on the command line. This limitation is the same for literal and regex searches. If a search string must contain extended ASCII, then the /G:FILE option should be used instead.
  2. FINDSTR may fail to find a file if the name contains extended ASCII characters and the file name is specified on the command line. If a file to be searched contains extended ASCII in the name, then the /F:FILE option should be used instead.

Here is a complete list of extended ASCII character transformations that FINDSTR performs on command line strings. Each character is represented as the decimal byte code value. The first code represents the character as supplied on the command line, and the second code represents the character it is transformed into. Note - this list was compiled on a U.S machine. I do not know what impact other languages may have on this list.

158 treated as 080 199 treated as 221 226 treated as 071 169 treated as 170 200 treated as 043 227 treated as 112 176 treated as 221 201 treated as 043 228 treated as 083 177 treated as 221 202 treated as 045 229 treated as 115 178 treated as 221 203 treated as 045 231 treated as 116 179 treated as 221 204 treated as 221 232 treated as 070 180 treated as 221 205 treated as 045 233 treated as 084 181 treated as 221 206 treated as 043 234 treated as 079 182 treated as 221 207 treated as 045 235 treated as 100 183 treated as 043 208 treated as 045 236 treated as 056 184 treated as 043 209 treated as 045 237 treated as 102 185 treated as 221 210 treated as 045 238 treated as 101 186 treated as 221 211 treated as 043 239 treated as 110 187 treated as 043 212 treated as 043 240 treated as 061 188 treated as 043 213 treated as 043 242 treated as 061 189 treated as 043 214 treated as 043 243 treated as 061 190 treated as 043 215 treated as 043 244 treated as 040 191 treated as 043 216 treated as 043 245 treated as 041 192 treated as 043 217 treated as 043 247 treated as 126 193 treated as 045 218 treated as 043 249 treated as 250 194 treated as 045 219 treated as 221 251 treated as 118 195 treated as 043 220 treated as 095 252 treated as 110 196 treated as 045 222 treated as 221 254 treated as 221 197 treated as 043 223 treated as 095 198 treated as 221 224 treated as 097 

Any character >0 not in the list above is treated as itself, including <CR> and <LF>. The easiest way to include odd characters like <CR> and <LF> is to get them into an environment variable and use delayed expansion within the command line argument.

Character limits for strings found in files specified by /G:FILE and /F:FILE options
The nul (0x00) character can appear in the file, but it functions like the C string terminator. Any characters after a nul character are treated as a different string as if they were on another line.

The <CR> and <LF> characters are treated as line terminators that terminate a string, and are not included in the string.

All other single byte characters are included perfectly within a string.

Searching Unicode files
FINDSTR cannot properly search most Unicode (UTF-16, UTF-16LE, UTF-16BE, UTF-32) because it cannot search for nul bytes and Unicode typically contains many nul bytes.

However, the TYPE command converts UTF-16LE with BOM to a single byte character set, so a command like the following will work with UTF-16LE with BOM.

type unicode.txt|findstr "search" 

Note that Unicode code points that are not supported by your active code page will be converted to ? characters.

It is possible to search UTF-8 as long as your search string contains only ASCII. However, the console output of any multi-byte UTF-8 characters will not be correct. But if you redirect the output to a file, then the result will be correctly encoded UTF-8. Note that if the UTF-8 file contains a BOM, then the BOM will be considered as part of the first line, which could throw off a search that matches the beginning of a line.

It is possible to search multi-byte UTF-8 characters if you put your search string in a UTF-8 encoded search file (without BOM), and use the /G option.

End Of Line
FINDSTR breaks lines immediately after every <LF>. The presence or absence of <CR> has no impact on line breaks.

Searching across line breaks
As expected, the . regex metacharacter will not match <CR> or <LF>. But it is possible to search across a line break using a command line search string. Both the <CR> and <LF> characters must be matched explicitly. If a multi-line match is found, only the 1st line of the match is printed. FINDSTR then doubles back to the 2nd line in the source and begins the search all over again - sort of a “look ahead” type feature.

Assume TEXT.TXT has these contents (could be Unix or Windows style)

A A A B A A 

Then this script

@echo off setlocal ::Define LF variable containing a linefeed (0x0A) set LF=^ ::Above 2 blank lines are critical - do not remove ::Define CR variable containing a carriage return (0x0D) for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a" setlocal enableDelayedExpansion ::regex "!CR!*!LF!" will match both Unix and Windows style End-Of-Line findstr /n /r /c:"A!CR!*!LF!A" TEST.TXT 

gives these results

1:A 2:A 5:A 

Searching across line breaks using the /G:FILE option is imprecise because the only way to match <CR> or <LF> is via a regex character class range expression that sandwiches the EOL characters.

  • [<TAB>-<0x0B>] matches <LF>, but it also matches <TAB> and <0x0B>
  • [<0x0C>-!] matches <CR>, but it also matches <0x0C> and !

Note - the above are symbolic representations of the regex byte stream since I can’t graphically represent the characters.

Answer continued in part 2 below…