FIND
suggest changeSearches for a string in files or input, outputting matching lines. Unlike FINDSTR, it cannot search folders recursively, cannot search for a regular expression, requires quotation marks around the sought string, and treats space literally rather than as a logical or.
Examples:
find "(object" *.txt
dir /S /B | find "receipt"
dir /S /B | find /I /V "receipt"
Prints all non-matching lines in the output of the
dir
command, ignoring letter case.find /C "inlined" *.h
Instead of outputting the matching lines, outputs their count. If more than one file is searched, outputs one count number per file preceded with a series of dashes followed by the file name; does not output the total number of matching lines in all files.
find /C /V "" < file.txt
Outputs the number of lines AKA line count in
file.txt
. Does the job ofwc -l
of other operating systems. Works by treating "" as a string not found on the lines. The use of redirection prevents the file name from being output before the number of lines.type file.txt | find /C /V ""
Like the above, with a different syntax.
type *.txt 2>NUL | find /C /V ""
Outputs the sum of line counts of the files ending in
.txt
in the current folder. The2>NUL
is a redirection of standard error that removes the names of files followed by empty lines from the output.find "Schönheit" *.txt
If run from a batch file saved in unicode UTF-8 encoding, searches for the search term "Schönheit" in UTF-8 encoded *.txt files. For this to work, the batch file must not contain the byte order mark written by Notepad when saving in UTF-8. Notepad++ is an example of a program that lets you write UTF-8 encoded plain text files without byte order mark. While this works with find command, it does not work with FINDSTR.
find "Copyright" C:\Windows\system32\a*.exe
Works with binary files no less than text files.
Links:
$ find /?
Searches for a text string in a file or files.
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.