Sunday, September 16, 2012

Find String in Files using Dos command

FINDSTR
Search for strings in files.



Syntax

FINDSTR [options] [/F:file] [/C:string] [/G:file]

[/D:DirList] [/A:color] [/OFF[LINE]] [string(s)] [pathname(s)]



FINDSTR [options] [/F:file] [/R] [/G:file]

[/D:DirList] [/A:color] [/OFF[LINE]] [string(s)] [pathname(s)]

Key

string Text to search for.

pathname(s) The file(s) to search.

/C:string Use string as a literal search string.

/R Use string as a regular expression.

/G:file Get search string from a file (/ stands for console).

/F:file Get a list of pathname(s) from a file (/ stands for console).

/A:color Display filenames in colour (2 hex digits)

/d:dirlist Search a comma-delimited list of directories.



options may be any combination of the following switches:

/I Case-insensitive search.

/S Search subfolders.

/P Skip any file that contains non-printable characters

/OFF[LINE] Do not skip files with the OffLine attribute set.

/L Use search string(s) literally.

/B Match pattern if at the Beginning of a line.

/E Match pattern if at the END of a line.

/X Print lines that match exactly.

/V Print only lines that do NOT contain a match. /N Print the line number before each line that matches.

/M Print only the filename if a file contains a match.

/O Print character offset before each matching line.


Example:

C:/Docs/test> findstr /I /S /P /M "Venkata Naresh" *

Explanation:

Search "Venkata Naresh" in all the files in folder "C:/Docs/test".




No comments: