Jump to content

findstr

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
findstr
Other namesqgrep
Developer(s)Microsoft,ReactOS Contributors
Operating systemWindows,ReactOS
PlatformCross-platform
TypeCommand
LicenseWindows:Proprietarycommercial software
ReactOS:GNU General Public License
Websitedocs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr

Incomputing,findstris acommandin thecommand-line interpreters(shells) ofMicrosoft Windows[1][2]andReactOS.[3]It is used to search for a specifictext stringincomputer files.[4]

Overview

The command sends the specified lines to thestandard outputdevice.[5] It is similar to thefindcommand. However, while thefindcommand supportsUTF-16,findstrdoes not. On the other hand,findstrsupportsregular expressions,whichfinddoes not. Thefindstrprogram was first released as part of theWindows 2000Resource Kitunder the nameqgrep.[6]

findstrcannot search fornull bytescommonly found inUnicodecomputer files.[7]

Syntax

FINDSTR flags strings [drive:][path]filename[...]

Arguments:

  • flagsThis can be any combination of flags described below.
  • stringsText to be searched for.
  • [drive:][path]filenameSpecifies a file or files to search.

Flags:

  • /BMatches pattern if at the beginning of a line.
  • /EMatches pattern if at the end of a line.
  • /LUses search strings literally.
  • /RUses search strings as regular expressions.
  • /SSearches for matching files in the current directory and all subdirectories.
  • /ISpecifies that the search is not to be case-sensitive.
  • /XPrints lines that match exactly.
  • /VPrints only lines that do not contain a match.
  • /NPrints the line number before each line that matches.
  • /MPrints only the filename if a file contains a match.
  • /OPrints character offset before each matching line.
  • /PSkip files with non-printable characters.
  • /OFF[LINE]Do not skip files with offline attribute set.
  • /A:attrSpecifies color attribute with two hex digits. See "color /?"
  • /F:fileReads file list from the specified file(/ stands for console).
  • /C:stringUses specified string as a literal search string.
  • /G:fileGets search strings from the specified file(/ stands for console).
  • /D:dirSearch a semicolon delimited list of directories

Note: Following command displays the detailed help about this command:

FINDSTR /?

Example

Save your running services into file _services.txt and search in this file for lines containing word "network" - case insensitive:

@echooff
setsearchstr=network
net start>_services.txt
FINDSTR /I"%searchstr%"_services.txt
pause

output would be:

Network Connections
Network List Service
Network Location Awareness
Network Store Interface Service
Windows Media Player Network Sharing Service
Press any key to continue...

See also

References

  1. ^Microsoft WinXP documentation for findstr
  2. ^Microsoft Server 2012/2016 documentation for findstr
  3. ^"Reactos/Reactos".GitHub.16 October 2021.
  4. ^MS-DOS and Windows command line findstr command
  5. ^Excellent documentation on usage of findstr
  6. ^History of Findstr from Raymond Chen
  7. ^Findstr - Search for strings - Windows CMD - SS64.com

Further reading