Findstr command in Windows

The findstr command searches for text samples in files. For an example of how to use this command, please see the example below.

Command syntax findstr

 findstr [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:] [/c:] [/g:] [/d:] [/a:] [/off[line]] [:][][ .] 

Parameters

ParameterDescription / b Suitable for text samples if it is at the beginning of the line. / e Match the text sample if it is at the end of the line. / l Handle the search string literally. / r Handle the search string as a regular expression. This is the default setting. / s Search the current directory and all subdirectories. / i Ignore the case of characters when searching for strings. / x Print exact match lines. / v Print only lines that do not contain a match. / n Print the line number of each line with the appropriate result. / m Print only the file name if the file contains matches. / o Print offset characters before each matching line. / p Ignore files with unprintable characters. / off [line] Do not ignore files that have an offline property set. / f: Receive a list of files from the specified file. / c: Use the text specified as a literal search string. / g: Get a search string from the specified file. / d: Search for the specified directory list. Each directory must be separated by a semicolon (;), for example dir1;dir2;dir3 . / a: Specify color attribute with two hexadecimal digits. Please enter color /? For more details. Specify text to search in FileName. Necessary. [:] [] [.] Specifies the location and file or files to search. Request at least one file name. /? Show help at the command prompt.

Note

  1. All findstr command line options must precede Strings and FileName in the command string.
  2. Regular expressions use both letter and super characters to find text samples, instead of exact strings. The literal character is a character that has no special meaning in the regular expression syntax - it matches the appearance of that character. For example, letters and numbers are letter characters. A metacharacter is a symbol with special meaning (an operator or separator) in regular expression syntax.

The following table lists the characters that the findstr command accepts:

MetacharacterValue. Wildcard: Any character * Repeat: 0 or more occurrences of the previous character or class. ^ Line position: Line header $ Line position: End of line [class] Character class: Any one character in a set. [^ class] Inverse class: Any one character not in the set. [xy] Range: Any character in the specified range. x Exit: Use a super character x Word position: The end of the word

Special characters in regular expression syntax are most powerful when you use them together. For example, use the wildcard combination (.) And the repeating character (*) to match any character string:

 .* 

Use the following expression as part of a larger expression to match any string that begins with "b" and ends with "ing":

 b.*ing 

For example

Use spaces to separate multiple search strings, unless the argument is started with the parameter / c.

To search for "hello" or "there" in the xy file, enter:

 findstr "hello there" xy 

To search "hello there" in the xy file, enter:

 findstr /c:"hello there" xy 

To find all occurrences of the word "Windows" (with the initial capital letter W) in the Proposal.txt file, enter:

 findstr Windows proposal.txt 

To search for all files in the current directory and all subdirectories contained in Windows, regardless of the first capitalized or lowercase letter, enter:

 findstr /s /i Windows *.* 

To find all occurrences of lines starting with "FOR" and in front of no or multiple spaces (like in the computer program loop), as well as to display the number of lines that each occurrence found, enter:

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

To search multiple strings in a set of files, create a text file containing each search criterion on a separate line. You can also list the exact files you want to search in a newly created text file. For example, to use search criteria in the Stringlist.txt file, search for the files listed in Filelist.txt, then store the results in the Result.out file, enter:

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

To list all files that contain "computer" in the current directory and all subdirectories, regardless of the initial or lowercase initials, type:

 findstr /s /i /m "" *.* 

To list all files containing "computer" and any other words starting with "comp", (such as "compliment" and "compete"), enter:

 findstr /s /i /m "  

See more:

  1. The flattemp command in Windows
  2. Finger command in Windows
  3. Eventcreate command in Windows
4.1 ★ | 26 Vote

May be interested

  • Instructions for using Command PromptInstructions for using Command Prompt
    deep in windows is a command-line world that is obscure. in this article, we will show you how to solve errors and make your computer more secure.
  • Rd command in WindowsRd command in Windows
    the rd command helps delete a directory
  • Cmd command in WindowsCmd command in Windows
    the cmd command starts a new version of the command interpreter, cmd.exe. if used without parameters, cmd will display copyright information and the version of the operating system.
  • How to use the command history function in Command PromptHow to use the command history function in Command Prompt
    command prompt is an extremely familiar command for anyone using windows operating system. besides, a lot of current software also supports the command line to perform actions on the command prompt window, instead of on the screen.
  • The sfc command in WindowsThe sfc command in Windows
    (applies to windows server (semi-annual channel), windows server 2016, windows server 2012 r2, windows server 2012)
  • Reg command copy in WindowsReg command copy in Windows
    to copy an entry to the location specified on the local pc or the remote computer we will use the reg copy command. to learn more about how to use the reg copy command, you can track the syntax, explain the command parameters and the example tipsmake.com has compiled below.
  • Fc command in WindowsFc command in Windows
    the fc command compares two files or a collection of files and displays the differences between them.
  • The echo command in WindowsThe echo command in Windows
    the echo command displays the message or turns on / off the command repeat feature. if used without parameters, the echo command will display the current echo setting.
  • Xcopy command in WindowsXcopy command in Windows
    the xcopy command is a command prompt command used to copy one or more files or folders from one location to another. with many options and the ability to copy entire directories, the xcopy command is similar to, but much more powerful, than the copy command.
  • The cacls command in WindowsThe cacls command in Windows
    the cacls command displays or modifies an arbitrary access control list (dacl) on the specified file. the command applies to windows server (semi-annual channel), windows server 2016, windows server 2012 r2, windows server 2012.