FIND – Windows CMD Command
Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in /home/future4tech/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 119
Search for a text string in a file & display all the lines where it is found.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Syntax FIND [/V] [/C] [/N] [/I] "string" [pathname(s)] Key "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.
Errorlevel
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.
Limitations
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.
An empty string “” will normally match nothing, with the/v flag reversing the test, to match everything, but this will fail for any lines longer than 4091 characters long.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Examples: 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 (like wc -l on unix). The empty string "" is treated as never matching. The /v flag reverses the test, so now it matches everything and then /c returns the count: C:\> TYPE myfile.txt | FIND "" /v /c |
I’ve been absent for some time, but now I remember why I used to love this blog. Thank you, I will try and check back more frequently. How frequently you update your site?