Search for a text string in a file & display all the lines where it is found.
Syntax FIND [/V] [/C] [/N] [/I] "string" [pathname(s)]
"string" The text string to find (must be in quotes).
[pathname] A drive/file(s) to search (wildcards accepted). /V Display all lines NOT containing the specified string.
/C Count the number of lines containing the string.
/N Display Line numbers.
/I Ignore the case of characters when searching for the string. [/off[line]] Do not skip files that have the offline attribute set.
If a [pathname] is not specified, FIND will prompt for text input
or will accept text piped from another command.
(use CTRL-Z to end manual text input)
If searching for text that contains double quote characters " , they must be escaped by doubling to ""
This is in addition to enclosing the entire string in quotation marks: "The ""main"" event"
The FIND command will output a string of 10 dashes ---------- followed by the filename being searched, followed by any matching lines of text in the file.
FIND will return an ErrorLevel as follows:
0 String found in at least one of the files.
1 String not found
2 If any files in the list do not exist or if no files match a wildcard mask. An invalid switch is given.
Find does not support wildcards, use FINDSTR instead.
Although FIND can be used to scan large files, it will not detect any string that is positioned more than 1070 characters along a single line (with no carriage return) This makes it of limited use in searching binary or XML file types.
If names.txt contains the following:
Joe Bloggs, 123 Main St, Dunoon Arnold Jones, 127 Scotland Street, Edinburgh
To search for "Jones" in names.txt
C:\> FIND "Jones" names.txt
---------- NAMES.TXT Arnold Jones, 127 Scotland Street, Edinburgh
If you want to pipe the output from a command into FIND use this syntax
C:\> TYPE names.txt | FIND "Jones"
You can also redirect like this
C:\> FIND /i "Jones" < names.txt >logfile.txt
To search a folder for files that contain a given search string:
C:\> FOR %G IN (*.txt) do (find /n /i "SearchWord" "%G")
Count the number of lines in a file:
C:\> TYPE myfile.txt | FIND "" /v /c
“Instead of getting married again, I'm going to find a woman I don’t like and just give her a house” - Lewis GrizzardRelated: