FINDSTR

RECENT NEWS

12/18/2015 - Hello! We're excited to announce that Mental Works Computing Software will soon be featuring

12/11/2015 - We're going to announce Dr.Batcher 3.0 Alpha with batch files debugger support soon. If you want to start...

News history...

TESTIMONIALS

Rob van der Woude:
"Mental Works Computing Software has created a nice tool for...

Andrew Jaritsyn:
“I used to write batch files with the help of Notepad, but...

Steve H.:
“This tool helped me to write some batch files in a couple...

More...

FINDSTR

Searches for strings (text patterns) in files.

Syntax:

FINDSTR [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:File] [/c:String] [/g:File] [/d:DirList] [/a:ColorAttribute] [/off[line]] Strings [Drive:][PathFileName[ ...]

/b – matches the pattern if it is at the beginning of a line.

/e ‑ matches the pattern if it is at the end of a line.

/l – uses search strings literally.

/r – uses search strings as regular expression(s).

/i – case-insensitive search.

/x – prints lines matching exactly.

/s – searches all subdirectories of the current directory.

/v – displays lines that don’t contain the specified string(s).

/n – displays line numbers.

/m – displays file names only for files containing matches.

/o – displays the character offset before each match.

/p – skips files with non-printable characters.

/off and /offline – doesn’t skip files with offline attribute.

/f:File – gets the list of pathnames from the specified file.

/c:String – uses the String as the literal search string.

/g:File ‑ gets the search strings from the specified file.

/d:DirList – performs search in the specified list of directories.

/a:ColorAttribute – displays filenames with the specified color.

Strings ‑ the required text to search for.

[Drive:][Path]FileName – file(s) or folder(s) where you want to search for the specified text.

Usage:

FINDSTR supports regular expressions to search for certain text matching patterns. Here is the list of such expressions:

. ‑ Wildcard: any character

* ‑ Repeat: zero or more occurrences of the previous character or class

^ ‑ Line position: beginning of the line

$ ‑ Line position: end of the line

[class] ‑ Character class: any one character in a set

[^class] ‑ Inverse class: any one character not in a set

[x-y] ‑ Range: any characters within the specified range

\x ‑ Escape: literal use of a metacharacter x

\<string ‑ Word position: beginning of the word

string\> ‑ Word position: end of the word

For example, .* matches with any characters, and expression a.*z matches with any words starting with a and ending with z.

Processing search strings as regular expressions is the default setting for FINDSTR.

If search strings contain many words separated with spaces, FINDSTR will return search results with files containing ANY of these words.

If any matches were found, FINDSTR sets ERRORLEVEL to 0, in the other case it sets ERRORLEVEL to 1.

Examples:

Search for “Hello” or “world” in helloworld.c:

FINDSTR “Hello world” helloworld.c

Search for “back” but not “backup”:

FINDSTR “\<back\>” c:\somefile.txt

 

Subscribe batch files programming newsletter (no spam):

Subscribe

Unsubscribe