Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

findstr

Feedback

In this article

Searches for patterns of text 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>:][<path>]<filename>[ ...]

Parameters

ParameterDescription
/bMatches the text pattern if it is at the beginning of a line.
/eMatches the text pattern if it is at the end of a line.
/lProcesses search strings literally.
/rProcesses search strings as regular expressions. This is the default setting.
/sSearches the current directory and all subdirectories.
/iIgnores the case of the characters when searching for the string.
/xPrints lines that match exactly.
/vPrints only lines that don't contain a match.
/nPrints the line number of each line that matches.
/mPrints only the file name if a file contains a match.
/oPrints character offset before each matching line.
/pSkips files with non-printable characters.
/off[line]Does not skip files that have the offline attribute set.
/f:<file>Gets a file list from the specified file.
/c:<string>Uses the specified text as a literal search string.
/g:<file>Gets search strings from the specified file.
/d:<dirlist>Searches the specified list of directories. Each directory must be separated with a semicolon (;), for exampledir1;dir2;dir3.
/a:<colorattribute>Specifies color attributes with two hexadecimal digits. Typecolor /? for additional information.
<strings>Specifies the text to search for infilename. Required.
[\<drive>:][<path>]<filename>[...]Specifies the location and file or files to search. At least one file name is required.
/?Displays Help at the command prompt.

Remarks

  • Allfindstr command-line options must precedestrings andfilename in the command string.

  • Regular expressions use both literal characters and meta-characters to find patterns of text, rather than exact strings of characters.

    • A literal character is a character that doesn't have a special meaning in the regular-expression syntax; instead, it matches an occurrence of that character. For example, letters and numbers are literal characters.

    • A meta-character is a symbol with special meaning (an operator or delimiter) in the regular-expression syntax.

      The accepted meta-characters are:

      Meta-characterValue
      .Wildcard - Any character
      *Repeat - Zero or more occurrences of the previous character or class.
      ^Beginning line position - Beginning of the line.
      $Ending 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.
      \xEscape - Literal use of a meta-character.
      \<stringBeginning word position - Beginning of the word.
      string\>Ending word position - End of the word.

      The special characters in regular expression syntax have the most power when you use them together. For example, use the combination of the wildcard character (.) and repeat (*) character to match any string of characters:.*

      Use the following expression as part of a larger expression to match any string beginning withb and ending withing:b.*ing

  • To search for multiple strings in a set of files, you must create a text file that contains each search criterion on a separate line.

  • Use spaces to separate multiple search strings unless the argument is prefixed with/c.

Examples

To search forhello orthere in filex.y, type:

findstr hello there x.y

To search forhello there in filex.y, type:

findstr /c:"hello there" x.y

To find all occurrences of the wordWindows (with an initial capital letter W) in the fileproposal.txt, type:

findstr Windows proposal.txt

To search every file in the current directory and all subdirectories that contained the wordWindows, regardless of the letter case, type:

findstr /s /i Windows *.*

To find all occurrences of lines that begin withFOR and are preceded by zero or more spaces (as in a computer program loop), and to display the line number where each occurrence is found, type:

findstr /b /n /r /c:^ *FOR *.bas

To list the exact files that you want to search in a text file, use the search criteria in the filestringlist.txt, to search the files listed infilelist.txt, and then to store the results in the fileresults.out, type:

findstr /g:stringlist.txt /f:filelist.txt > results.out

To list every file containing the wordcomputer within the current directory and all subdirectories, regardless of case, type:

findstr /s /i /m \<computer\> *.*

To list every file containing the word computer and any other words that begin with comp, (such as compliment and compete), type:

findstr /s /i /m \<comp.* *.*

Related links


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?