Home
> Commands A-M
> Commands F
FINDSTR
Description
| Syntax
| Parameters
| Switches
| Related
| Notes
| Examples
| Errorlevels
| Availability
Search for strings in files.
Syntax
FINDSTR
/?
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)]
Parameters
- pathname(s)
(NT3.1)
- The file(s) to search.
- string(s)
(NT3.1)
- Text to search for. If multiple words
(separated by spaces) in string, can match ANY ONE of the
words.
Switches
- /?
(NTXP)
- Display help.
- /A:color_attribute
(NT2000)
- Specifies color attribute with two hex digits. See
Color.
- /B
(NT3.1)
- Match pattern if at the Beginning of a line.
- /C:string
(NT3.1)
- 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.1)
- Match pattern if at the END of a line.
- /F:file
(NT3.1)
- 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.1)
- 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.1)
- Case-insensitive search.
- /L
(NT3.1)
- Use search string(s) literally.
- /M
(NT3.1)
- Print only the filename if a file contains a match.
- /N
(NT3.1)
- Print the line number before each line that matches.
- /O
(NT3.1)
- Print character offset before each matching line.
- /OFFLINE
(NTXP)
- Processes files with offline attribute set.
- /P
(NT4)
- Skip any file that contains non-printable characters.
- /R
(NT3.1)
- Use search string(s) as regular expressions. This switch is not
required. FINDSTR will interpret all metacharacters as regular
expressions unless the /L switch is used:
- . Wildcard: any character
- * Repeat: zero or more occurances of previous character or class
- ^ Line position: beginning of line
- $ Line position: end of line
- [class] Character class: any one character in set
- [^class] Inverse class: any one character not in set
- [x-y] Range: any characters within the specified range
- \x Escape: literal use of metacharacter x
- \<xyz Word position: beginning of
- xyz\> Word position: end of word
- /S
(NT3.1)
- Search current folder and subfolders.
- /V
(NT3.1)
- Print only lines that do NOT contain a match.
- /X
(NT3.1)
- Print lines that match exactly.
Related
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.
Notes
none.
Examples
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:
FINDSTR /G:CRIT.TXT /F:FILES.TXT > RESULTS.OUT
Errorlevels
- 0 The search was completed successfully and at least one match was found
- 1 The search was completed successfully, but no matches were found
OR search was not completed successfully.
Availability
- External
-
- DOS
-
none
- Windows
-
none
- Windows NT
-
NT3.1
NT3.5
NT3.51
NT4
NT2000
NTXP
NT2003
Last Updated: 2006/12/01
Direct corrections or suggestions to:
Rick Lively