Home > Commands A-M > Commands F


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Search for strings in files.



FINDSTR [/A:color_attribute] [/B | /E] [/C:string] [/D:dir1;dir2;...] [/F:file] [/G:file] [/I] [/P] [/L | /R] [/M] [/N] [/O] [/OFFLINE] [/S] [/V | /X] [string(s)] [pathname(s)]

pathname(s) (NT3.5)
The file(s) to search.
string(s) (NT3.5)
Text to search for. If multiple words (separated by spaces) in string, can match ANY ONE of the words.

/? (NTXP)
Display help.
/A:color_attribute (NT2000)
Specifies color attribute with two hex digits. See Color.
/B (NT3.5)
Match pattern if at the Beginning of a line.
/C:string (NT3.5)
Use string as a literal search string. If multiple words (separated by spaces) in string, must match ALL of the words.
/D:dir1;dir2;... (NT2000)
Search a semicolon-delimited list of directories.
/E (NT3.5)
Match pattern if at the END of a line.
/F:file (NT3.5)
Get a list of pathname(s) from a file (/ stands for console). Multiple files (each file on a new line) to search can be specified with a source file.
/G:file (NT3.5)
Get search string from a file (/ stands for console). Multiple search criteria (each item on a new line) can be specified with a file.
/I (NT3.5)
Case-insensitive search.
/L (NT3.5)
Use search string(s) literally.
/M (NT3.5)
Print only the filename if a file contains a match.
/N (NT3.5)
Print the line number before each line that matches.
/O (NT3.5)
Print character offset before each matching line.
Processes files with offline attribute set.
/P (NT4)
Skip any file that contains non-printable characters.
/R (NT3.5)
Use search string(s) as regular expressions.
/S (NT3.5)
Search current folder and subfolders.
/V (NT3.5)
Print only lines that do NOT contain a match.
/X (NT3.5)
Print lines that match exactly.


FIND - Search for a text string in a file.
MUNGE - Find and Replace text within file(s).
Equivalent Linux BASH commands:
grep - Search file(s) for lines that match a given pattern.
gawk - Find and Replace text within file(s).
tr - Translate, squeeze, and/or delete characters.




search for "granny" OR "Smith" in MyFile.txt:

    FINDSTR "granny Smith" MyFile.txt

Search for "granny Smith" in MyFile.txt (effectively the same as the FIND command):

    FINDSTR /C:"granny Smith" MyFile.txt

Search every file in the current folder and all subfolders for the word "Smith", regardless of upper/lower case:

    FINDSTR /S /I smith" *.*

To find every line containing the word SMITH, preceeded by any number of spaces, and to prefix each line found with a consecutive number:

    FINDSTR /B /N /C:" *smith" *.*

Finding a string only if surrounded by the standard delimiters To find the word "computer", but not the words "supercomputer" or "computerise":

    FINDSTR "\<computer\>" MyFile.txt

Now assume you want to find not only the word "computer", but also any other words that begin with the letters comp, such as "computerise" or "compete":

    FINDSTR "\<comp.*" MyFile.txt

Use the search criteria in CRIT.TXT and search the files listed in FILES.TXT then store the results in the file RESULTS.OUT:




Windows NT
NT3.5 NT4 NT2000 NTXP NT2003