Howto: To search a folder for files that contain a given search string

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.

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

FIND "Jones" names.txt

———- NAMES.TXT
Arnold Jones, 127 Scotland Street, Edinburgh

If you want to pipe a command into FIND use this syntax

TYPE names.txt | FIND "Jones" 

You can also redirect like this

FIND /i "Jones" < names.txt >logfile.txt

To search a folder for files that contain a given search string

FOR %G IN (*.txt) do (find /n /i "SearchWord" "%G")

(ref http://ss64.com/nt/find.html)

Combining commands with redirection operators

You can create custom commands by combining filter commands with other commands and file names. For example, you can use the following command to store the names of files that contain the string “LOG”:

dir /b | find “LOG” > loglist.txt

The dir command’s output is sent through the find filter command. File names that contain the string “LOG” are stored as a list of file names (for example, NetshConfig.log, Logdat.svd, and Mylog.bat) in the Loglist.txt file.

To use more than one filter in the same command, separate the filters with a pipe (|). For example, the following command searches every directory on drive C:, finds the file names that include the string “Log”, and then displays them in one Command Prompt window at a time:

dir c:\ /s /b | find “LOG” | more

By using a pipe (|), you direct Cmd.exe to send the dir command output through the find filter command. The find command selects only file names that contain the string “LOG.” The more command displays the file names that are selected by the find command, one Command Prompt window at a time. For more information about filter commands, see Using filters”

ref: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.