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 exampledir1;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
- All findstr command line options must precede Strings and FileName in the command string.
- 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 wordSpecial 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:
- The flattemp command in Windows
- Finger command in Windows
- Eventcreate command in Windows
You should read it
- Del command in Windows
- Cmd command in Windows
- Fc command in Windows
- Command at in Windows
- The echo command in Windows
- Doskey command in Windows
- Set command in Windows
- Defrag command in Windows
- Eventcreate command in Windows
- Bitsadmin getdisplayname and bitsadmin geterror command in Windows
- Endlocal command in Windows
- Mapadmin command in Windows
Maybe you are interested
How to use the file search command on Windows, find saved files
How to delete search history on CH Play, hide searched content
How to turn off search personalization on Google
Instructions for creating ChatGPT Search shortcuts on iPhone
How to use Vlookup function in Excel to search and reference
Search Race: Is ChatGPT Threatening Google's Throne?