当前位置:网站首页>[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
2022-07-07 00:57:00 【dssgresadfsrgre】
One 、find command
1.1 Print find Command help information
Carry out orders 【find /?】.
C:\Users\Administrator>find /?
Search for strings in files .
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines that do not contain the specified string .
/C Show only the number of lines that contain the string .
/N According to the line Numbers .
/I Ignore case when searching for Strings .
/OFF[LINE] Don't skip files with offline property sets .
"string" Specifies the text string to search for .
[drive:][path]filename
Specify the files to search for .
If no path is specified ,FIND Type the search at the prompt
Or text generated by another command .
1.2 Field string and filepath The grammar of
find The command does not recognize carriage return . When using find When searching for text in a file containing a carriage return , The search string must be limited to text that can be found between carriage returns , That is, a string that cannot be interrupted by a carriage return . for example ,“tax” And “file” When a carriage return occurs between ,find No report found “tax file” character string . let me put it another way ,find Only for strings on the same line , Cannot find character blocks that cross lines .
To find a string that encloses text in quotation marks , You must first enclose the entire string in quotation marks . secondly , Each quotation mark contained in the string must be enclosed by two double quotation marks . To be in Report.doc Search for 【abc"def"gh】, Please type the :
find "abc""def""gh" report.doc
If you want to filter by multiple criteria , Find both strings in the text file A It also includes string B The line of , With the help of pipe symbols , For details, see 1.8 Section .
Field string Wildcard characters are not supported , If you want to search including strings A Or a string B The line of , Can use for command .
for %f in (abc def) do find "%f" test.txt
Field filepath Support for wildcards , As for why some online articles say they don't support , Need to match for Command statements use , I'm not sure , Probably because cmd The reason of version iteration !
See 1.3.2 Section view fields filepath Wildcard usage of .
1.3 Basic usage :find "string" filepath
In a text file , Or search for information on the line of a string in a pile of text files .
1.3.1 Find English characters in a single file
for example , lookup tool.txt There is a string in the text file 【AA】 The line of .
Carry out orders 【find "AA" tool.txt】, The results are shown below ( If there is Chinese in the text file , You need an order chcp 65001 First switch to utf8 code , Otherwise, the result shows garbled ).
1.3.2 Find Chinese characters in multiple files
Before deciding to find Chinese characters , Be sure to use chcp 65001 Turn on utf8 code , Otherwise you won't be able to search .
command find Of string Field does not support wildcards , That is, if 【find "A?" tool.txt】, Finally, it will not show any lines with "A?", Because the question mark is treated as a common question mark .
however filepath Fields support wildcards , That is, if 【find " Towards " tool*.txt】, Finally, all tool Named at the beginning txt file .
1.4 Case insensitive —— Parameters /i
The default is case sensitive , When adding parameters /i Then there is no distinction .
on top 1.2 Section based on the text file , Carry out orders 【find /i "aa" "tool?.txt"】, give the result as follows .
Parameters /i It can be matched with any other parameters , There will be no logical contradictions and conflicts .
1.5 Search for lines that do not include the specified string —— Parameters /v
The default search includes the lines of the specified string , When adding parameters /v Then reverse search .
on top 1.2 Section based on the text file , Carry out orders 【find /v "AA" "tool.txt"】, give the result as follows .
Parameters /v It can be matched with any other parameters , There will be no logical contradictions and conflicts .
1.6 Add line label —— Parameters /n
No label by default , Only the text content of the line is displayed , When adding parameters /n Then additional label ( Not just labels ).
on top 1.2 Section based on the text file , Carry out orders 【find /n "AA" "tool.txt"】, give the result as follows .
Parameters /n It can be matched with any other parameters , There will be no logical contradictions and conflicts .
1.7 Show only the number of target rows —— Parameters /c
By default, only the text content of the line is displayed , When adding parameters /c After that, only the number of lines with strings is displayed .
c yes count Abbreviation , To count .
on top 1.2 Section based on the text file , Carry out orders 【find /c "AA" "tool.txt"】, give the result as follows .
Parameters /c In addition to and parameters /n contradiction , Nothing else is contradictory . If some people add these two parameters when writing , Whatever the order , Finally, there are only parameters /c Will take effect .
Help information on parameters /c There is something wrong with the description of , More accurately, it should be 【 Show only the number of rows 】, Because it can be compared with parameters /v Together , Express 【 Show only the number of lines that do not include strings 】, perform 【find /c /v "AA" "tool.txt"】 The results are as follows .
1.8 Cooperate with pipeline command ( Pipe, ) Use
The output result of the statement on the left of the pipe character , Will be input to the statement on the right .
find It supports the use with pipe symbols , If the right side of the pipe symbol is find sentence , Then the output string text on the left will be used as the right find Statement's lookup object .
find "abc" test.txt | find "xyz"
The above sentence means test.txt Find the string that exists at the same time abc And string xyz The line of , I.e. implementation Multiple filtration .
1.9 Search the online typing string as a real-time filter
About real-time filters , stay 1.1 The help information printed in the section is as follows ↓↓↓↓
If no path is specified ,FIND Text typed at the prompt or generated by another command will be searched .
in other words , Do not give text file path 、 Nor is it connected to the end of the pipe symbol , You can only use the keyboard to input the string line in real time .
Carry out orders 【find "abc"】, The cursor flashes at the head end .
Hit any one without abc Character serial ——【123456789】, And then go back .
Playing a game with abc Character serial ——【I miss you, abc!】, And then go back .
You can find , This line of string is output intact , That means it passed “ A severe test ”, Ha ha ha ha ...
After entering , How to exit the filter ? Use shortcut keys 【ctrl+c】, command 【exit】 Can't quit .
Two 、findstr command
findstr Command is better than find Commands are even stronger , Because it also supports regular expressions , It can be called “ The strong among the strong ”.
2.1 Print findstr Command help information
C:\Users\Administrator>findstr /?
Looking for strings in a file .
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B At the beginning of a line, pairing mode .
/E Pairing patterns at the end of a line .
/L Use search strings by word .
/R Use the search string as a general expression .
/S Search the current directory and all subdirectories for matching files .
/I Specifies that the search is case insensitive .
/X Print exactly matched lines .
/V Print only lines without matching .
/N Print the number of lines before each matched line .
/M If the file contains a match , Print only its file name .
/O Print character offset before each matching line .
/P Ignore files with non printable characters .
/OFF[LINE] Do not skip files with offline property sets .
/A:attr Specifies a color property with a hexadecimal number . Please see "color /?"
/F:file Read the list of files from the specified file (/ On behalf of the console ).
/C:string Use the specified string as the text search string .
/G:file Gets the search string from the specified file . (/ On behalf of the console ).
/D:dir Find a semicolon delimited list of directories
strings Text to find .
[drive:][path]filename
Specify the file to look for .
Unless the parameter has /C Prefix , Please use spaces to separate search strings .
for example : 'FINDSTR "hello there" x.y' In the file x.y Search for "hello" or
"there".'FINDSTR /C:"hello there" x.y' file x.y seek
"hello there".
Quick reference to general expressions :
. wildcard : Any character
* repeat : Previous characters or classes appear zero or more times
^ Row position : The beginning of the line
$ Row position : The end of the line
[class] Character class : Any character in the character set
[^class] Complement character class : Any character that is not in the character set
[x-y] Range : Any character within the specified range
\x Escape: Metacharacters x The use of words in English
\<xyz Word position : The beginning of the word
xyz\> Word position : The end of the word
of FINDSTR Details of common expressions , See online Command Reference .
(1) Yes /d:dir Additional instructions for , The original help information is not very intuitive , for instance 【/d:dir1;dir2;dir3】.
(2) For parameters /r Additional instructions for , Now the default is not to add , No addition string It will also be recognized as regular expressions ( General expressions ) Of . Maybe this parameter field was added originally strings Is a regular expression , After the revision, this parameter remains . It's a legacy of history .
2.2 Field strings And parameters /r、 Parameters /g:file
2.2.1 Field strings And parameters /c:string
Field strings Is used to specify the search string , I wonder if you noticed that this word is plural ?
In fact, this means fields strings Multiple strings are allowed , The strings are separated by spaces , for example 【abc def ghi】, Search separately 【abc】、【def】、【ghi】, For a certain line, just search one of them , Would pass .
If the field strings There is only one string ( There are no spaces 、 There is no special symbol ), Without quotation marks .
If the field strings Are multiple strings separated by spaces , Or there are special symbols in a single string ( such as &), You need quotation marks .
And the parameters /c:string The noun form of is singular , This also means that once parameters are added /c, You can only search a single string , For details, see 2.4.2 Section .
Field strings And parameters /c:string, Both support regular expressions ( Wildcards are not to mention ), See the next section .
2.2.2 Regular expressions and parameters /r
stay findstr In the command statement , The typical regular expression rules supported are as follows :
. wildcard : Any character
* repeat : Previous characters or classes appear zero or more times
^ Row position : The beginning of the line
$ Row position : The end of the line
[class] Character class : Any character in the character set
[^class] Complement character class : Any character that is not in the character set
[x-y] Range : Any character within the specified range
\x Escape: Metacharacters x The use of words in English
\<xyz Word position : The beginning of the word
xyz\> Word position : The end of the word
The above 10 The first sign is “ Metacharacters ”, It has special meaning in regular expression grammar ( Operator or separator ) The symbol of .
( ordinary )“ Text character ” Is a character that has no special meaning in regular expression syntax , Is the basic item of the matching string . for example ,26 Letters and 10 All numbers are literal characters ( Text character ).
(1) Wildcards and repetition characters (.、*)
【.】 The number is a wildcard , Represents an arbitrary character .
【*】 No. is a repetition character , It does not represent any character in regular expressions , It's the number of repetitions of the left character or expression ,【*】 The sign indicates that the number of repetitions is zero or more .
【.*】 For any character , It can be zero characters , It's also multiple .
The following is a classic application case of wildcards and repetition characters .
have only 【.】 Time of signal ,【.】 The number of symbols indicates the minimum number of characters in the matching line , for example 【.】 What matches is a line with at least one character , and 【.....】 What matches is at least 5 Character lines .
From file tool.txt Find any character in , Do not include empty characters or empty lines , Can execute orders 【findstr . tool.txt】 or 【findstr "." tool.txt】.
From file tool.txt Find any character in , Including blank characters and blank lines , Can execute orders 【findstr .* tool.txt】 or 【findstr ".*" tool.txt】.
(2) Find any character in the character set ([class]、[^class]、[x-y])
class The formal representation can be separated discretely and independently , for example 【aef】; The minus sign means take ASCII Characters encoded between left and right symbols , for example [e-h] Means to take from e To h Between the letters ( Case insensitive ); and ^ Represents the complement of the following character set .
Generally, you can only use ASCII character ( It can't be Chinese characters ); In addition, for some special characters , Need to escape .
For English quotation marks 【"】, Need to escape ; If it is a single quotation mark , The just 【"""】, That is to say ["""].
For minus sign 【-】 There is no need to escape , Just write it in discrete form , such as [-a-z] Means to match any letter plus a minus sign .
If you insert wildcards into the character set 【.】 And repetition 【*】, It will put 【.】 and 【*】 Treat as normal characters , There is no meaning of wildcard and repetition .
From file tool.txt The search in includes a、b、c、e、z、y Letter String or line , Executable command 【findstr "[abcezy]" tool.txt】.
From file tool.txt Mask strings or lines that do not conform to the rules , If it is Pure numeric strings or lines are filtered out and not displayed ( for example 237623), If it contains non numeric characters, it is reserved ( such as 34yht888), Executable command 【findstr "[^0-9]" tool.txt】.
From file tool.txt Search for Lowercase characters a-f,l-z String , That is, it does not include g h I j k These letters , Executable command 【findstr "[a-fl-z]" tool.txt】.
From file tool.txt The search in includes Arbitrary number String or line , Executable command 【findstr "[0-9]" tool.txt】.
From file tool.txt The search in includes Any letter String or line , Executable command 【findstr "[a-z]" tool.txt】, Note that there is no need to write 【findstr "[a-zA-Z]" tool.txt】, Because if it is x-y In the form of , The default is case insensitive . And if it is similar [abc] This discrete form , It is case sensitive .
From file tool.txt The middle match consists of two Character set combination Such as MahY , MbiY, MahY etc. ….., Executable command 【findstr "M[abc][hig]Y" tool.txt】.
(3) The beginning and end of a line and the beginning and end of a word (^、$、\<、\>)
In the help message ,“ word ” Corresponding to English prototype word, So Chinese Translation “ The word can also be replaced with “ word ”, Directly use the prefix and suffix in the subtitle to enhance the intuition .
The line anchor is ^ and $, Corresponding to the beginning and end of the line respectively , The word anchor is \< and \>, Corresponding to the beginning and end of the word respectively .
The head and tail of the line , That is, the starting position and the ending position , It's easy to understand .
Here's an example , Help you understand the head and tail anchors of lines .
^ Indicates the beginning of the line ,"^step" Match only "step hello world" The first word in ;$ End of line ,"step$" Match only "hello world step" The last word in .
Here's an example , Help you understand the head and tail anchors of words .
text file 【tool.txt】 There are two behaviors in "abcd" and "abcd e".
Carry out orders 【findstr "cd\>" tool.txt】, Both lines will appear , As long as they are connected ( Not opened by the space ) Combined with cd At the end of the ( It is not required to be the end of the line ) All satisfied with , It's equivalent to cd The line of the ending word will be found .
These two lines begin and end with anchors , It is often used to filter out pure numbers or letters .
For example, you want to filter tool.txt In the text file Pure number String or line , Executable command 【findstr "^[0-9]*$" tool.txt】,
for example 【675758345】 Will be preserved , and 【46752kkjl4】 It was filtered out .
For example, you want to filter tool.txt In the text file Pure letter String or line , Executable command 【findstr "^[a-z]*$" tool.txt】,
for example 【hythdfgdgiuf】 Retain , and 【956sdsftgruylk】、【1321argad13】 It's filtered out .
Line beginning and end anchor 【^、$】 Match repetition 【*】, Realize string or line matching multiple quantity symbols
If not in the search string 【*】 Number , That is to say, do not repeat the search criteria on the left .
for example 【^[0-9]】 Match any string or line with a number at the beginning of the line , and 【[a-zA-Z]$】 Match any string or line with letters at the end of the line .
If the anchor at the beginning and end of the line is added at the same time , That is, the beginning and end of the line are limited at the same time , Then there are several brackets corresponding to several characters . for example 【^[0-9]$】 Only rows with only one number will be matched , and 【^[0-9][A-Za-z]$】 Only the first character will be matched to a number 、 The second character is the line of letters .
(4) Escape of metacharacters ——/x(escape To signify an escape )
We mentioned above that meta characters include wildcards 【.】、 Repetition character 【*】、 Any symbol 【[】 and 【]】、 Continuous character 【-】、 Complement character 【^】、 Line beginning and end anchor 【^】 and 【$】、 Initial and final characters 【/<】 and 【>/】.
If the metacharacter is compared to x, So if we want to match the normal text form of metacharacters , It can be used 【/x】; For example, for continuous characters 【-】 The escape of , The corresponding is 【/-】.
In addition, this article will be wordy for many times —— For the escape of double quotation marks , Use double quotes , That is to say 【"】 Need to escape into 【"""】,【abc"def】 To be written 【abc"""def】.
For forward slash 【/】 The escape of , Same as double quotation marks , Solve it by itself , That is to say 【/】 Need to escape into 【//】.
2.2.3 Parameters of string Batch Search /g:filepath
Parameters /g After filepath It's a text file , Each line represents a search string .
from tool.txt The file changes slightly , Generate goal.txt file .
Then , Then execute the order 【findstr /g:goal.txt tool.txt】, give the result as follows , Finally, we found two matching lines .
2.3 Field filepath And parameters /d:dir1;dir2、 Parameters /f:file、 Parameters /s
2.3.1 Search location —— Field filepath
Of this section filepath It refers to the fields in the help information [[drive:][path]filename[ ...]], The simplified version is true !
Field strings The search string is specified , That is, what to search ; And fields filepath The search location is specified , That is, where to search .
You can take an absolute path , You can also use the relative path .
You can not only search a single text file , You can also search multiple text files , At this time, the path strings of different files should be separated by spaces .
in addition filepath Wildcard characters are also supported 【*】 And wildcards 【?】.
For example, execute command 【findstr /r "abc dedgth.t" tool?.txt】, The final result includes tool.txt and too1.txt Information about .
Another example is to execute orders 【findstr /r "abc" *.*】 or 【findstr /r "abc" "*.*"】, Will be in All files in the current directory in Search for Whether there is a string abc.
2.3.2 Search in one or more directories —— Parameters /d:dir1 dir2 dir3
How to use this parameter , Write the code according to the help message , It should be easy to achieve , But in the end, we can't effectively see the expected effect .
Execute the order first 【findstr /r /s "AA" *.*】, Find the files in the current directory and all its subdirectories that contain AA The line of .
Then execute the order 【findstr /r /s "AA" /d:dir1;dir2】, But the error is reported and the directory cannot be found .
Change to absolute Directory , perform 【findstr /r "AA" /d:D:\D-desktop\test5\dir1;D:\D-desktop\test5\dir2】, I still can't .
--------------------- Update the dividing line ----------------------------
After some exploration , I finally understand .
Original parameters /d:dir1;dir2;dir3 Can't put strings Behind ; It turns out that even if parameters are added /d:dir1;dir2;dir3, Must also be given filepath Matching rules of .
So the parameter /d:dir1;dir2;dir3 What is given is only the starting search directory , When adding this parameter , Default to CMD The current directory is used as the starting search directory ; The starting search directory refers to the subdirectory “ The starting point ”.
And the reason why we have to specify filepath Matching rules , The reason is to avoid too many non text files in the directory , This search is extremely time-consuming and labor-intensive , In addition, it can also improve the diversity of matching rules and the accuracy of matching .
Carry out orders 【findstr /r /d:dir1;dir2;dir3 "AA" *.*】 after , give the result as follows , Very successful !!!
2.3.3 Borrow the path provided by the text file ( Catalog ) To search for —— Parameters /f:file
Create a new text file , The contents are as follows , front 3 Lines are relative paths to files , The last line is a relative directory path
next , We don't care about the specified file path , But is the directory path like 2.3.2 The section also needs to specify the matching rule later ?
Might as well try. , We carry out orders 【findstr /r /f:paths.txt "AA" "*.*"】, give the result as follows
If no matching rule is specified , Carry out orders 【findstr /r /f:paths.txt "AA"】, Finally, there will be no search results for the current directory .
later , I reflect on myself , Is it a parameter /f:filepath Directory paths are not supported ? Look back at the help information ,“ Read file list ” Instead of reading the folder list , So the official meaning should not support reading folders inside .
/F:file Read the list of files from the specified file (/ On behalf of the console ).
2.3.4 The search scope goes deep vertically , Expand to subdirectories —— Parameters /s
If you don't add parameters /s, Carry out orders 【findstr /r "AA" *.*】, You can only find all files that meet the rules in the current directory .
Execute the order first 【findstr /r /s "AA" *.*】, Find the files in the current directory and all its subdirectories that contain AA The line of .
2.4 Search method parameters /b、/e、/c、/l、/i、/x、/v、
2.4.1 Line beginning and end positioning parameters —— Parameters /b、/e
The function of locating parameters in this section is actually the same as that of metacharacters of regular expressions 【^】、【$】 The function is exactly the same , The search string can only be searched and matched close to the beginning or end of the line .
For example, add parameters /b, You must put the search string at the beginning of the line to match , And a certain line is 【rfgwercd fwerfreg】, We can order 【findstr /l "fwerf" tool.txt】 Find this line , But you can't use commands 【findstr /l /b "fwerf" tool.txt】 find out .
Empathy , Parameters /e As the end of line positioning parameter , The implementation mechanism is also very simple .
Parameters /b And parameters /e You can add , Because there is no conflict , A search string can be close to the beginning or end of the line .
2.4.2 Search string with spaces , Parameters to be added /c
If the search string has spaces , for instance 【A B C】, that cmd By default, the program will search for strings in turn in the search source 【A】、【B】、【C】, As long as one of them meets the rules , Would pass .
But if the string we are searching for itself has spaces , In other words, you need to search with spaces ?
You need parameters /c 了 , And it needs to be written as /c:string In the form of . We can c as connect Abbreviation , The strings on both sides of the space are connected into a whole , This memorizes parameters /c Stronger .
By order 【findstr /c:"ab c" tool.txt】 For example , The last search should really include 【ab c】 String or line ; And if you don't add parameters /c, It's written in 【findstr "ab c" tool.txt】, So similar 【abasdref】、【cdsagrgtr】 The string or line of will also be passed .
2.4.3 Search strings as words —— Parameters /l
I don't understand how to use this parameter .
If the search string is part or all of a word , And this word appears on a certain line , Then this industry is indeed approved .
And if there are spaces in the search string , That is, there are multiple words , At this time, they will be searched separately , As long as the string in a certain line happens to have one of these words ( Partial match or perfect match ), Will be passed .
Parameters /l Can it be related to parameters /c collocation ? Try to execute the order 【findstr /l /c:"wercd fwerf" tool.txt】, The results are as follows . Will also pass , I am particularly puzzled about this , Because since you search by word , A word cannot have spaces , There are spaces in the search string and parameters /c Limited to a whole , Finally, treat it as a word , Isn't it absurd ?
From the test above , I can't see any added parameters /l The meaning of , It feels the same whether you add it or not .
2.4.4 Whole line matching , The beginning and end of the line are close to —— Parameters /x
What is whole line matching ? That is, the string to be searched occupies one line , Not part of it .
It is also easy to get , This matching pattern is actually the same as the first and last line matching , That is, below 3 The execution result of this command is exactly the same .
findstr /e /b "fg" tool.txt
findstr /x "fg" tool.txt
findstr "^fg$" tool.txt
2.4.5 Case insensitive —— Parameters /i
findstr Command statements are case sensitive by default , If you want to make no distinction , Parameters can be added /i.
Parameters i yes ignore Abbreviation , Said to ignore , Ignore the case , Isn't it case insensitive ?
Carry out orders 【findstr /i "aa" tool.txt】, The results of the final search include AA.
2.4.6 Search the complement of the target string —— Parameters /v
The default is what to search , Output ( Show ) what , This is the time to choose what you want ; But there is a case that the target cannot be output ( Show ), At this point is to choose what not to .
Add parameter /v, Carry out orders 【findstr /v "AA" tool.txt】, Those with AA The lines of the string will be discarded .
2.5 Display option parameters /m、/n、/o
Display option parameters /m、/n、/o Just change the display style , Do not change the contents of the text file .
These three parameters do not conflict with any other parameters ; But the parameters /m And parameters /n、 Parameters /o There are conflicts , Because only displaying the file name means that the sequence number of the line where the string is located cannot be displayed 、 You cannot display string offset values .
Parameters /m Indicates that only file name ,
Parameters /n Presentation display Line number ,
Parameters /o Indicates the offset value of the display target string from the beginning of the file ( Offset bytes , Instead of offsetting the number of characters ).
about ASCII character , A character is a byte ( Such as spaces ), Invisible carriage return 、 The newline character takes two bytes , But for Chinese symbols or Chinese characters , A Chinese character corresponds to 2-4 Bytes .
3、 ... and 、find Command and findstr Distinction of command
3.1 find The command supports counting the total number of rows
find The command supports parameters /c( Show only the number of matching rows ), You can count the number of rows that meet the rules .
for example 【find /c "A" tool.txt】 You can count test.txt It contains a string abc The total number of rows of , and findstr The command does not directly provide this function , Need to cooperate with for Statement to achieve .
findstr Parameters of the command statement /c The function is not counting (count), It's about connecting (connect) ; Parameters /c Followed by string Spaces are allowed , Instead of treating it as two strings .
3.2 find The command supports finding Unicode character
Generally speaking, these can be compared with ASCII Compatible characters , The special language of a country ( For example, simplified Chinese 、 Japanese 、 Korean ) Commonly used Utf8 code , So if you want to check, except ASCII Characters outside the encoding range , It needs to be used. find command .
find Yes " How ", however findstr We can't find out .
If you want to search unicode character , And want something similar findstr The power of commands , You can download a third-party program ——GNU Grep for windows, detailed See download official website .
3.3 find The command supports filtering special characters
The ideas in this section come from the Internet , Probably 2012 Year is very popular ; I don't know why I can't realize , May be cmd The command has been updated ? I don't say much nonsense , Quote their views , Here are the old pickles for the audience .
find You can filter some special characters , and findstr No way. .
such as , We are using 【fsutil fsinfo drives】 Statement when querying disk partitions , If you want the drive letter to be displayed separately instead of on the same line Hou ( In use for Statement is very useful when extracting drive letters ),find You can show your skill , and findstr I can only stare .
The specific code is :【fsutil fsinfo drives|find /v ""】, The output is as follows .
If change to findstr, You're going to report a mistake .
although find The results are not displayed in multiple lines , however findstr There was no result . Probably 2012 That's what netizens in said about advantage ?
3.4 findstr Ordered string Fields support wildcards
In the search string ,find You cannot use wildcards (* and ?) .
To use wildcards and regex Pattern search string , Only use findstr command , Or download third-party programs grep.
3.5 find The command cannot read the alternate data stream
find The command cannot read the alternate data stream .
To search in alternate data streams , Please use findstr、more or for /f command .
The above quote , come from Microsoft official website on find Comments for the command .
So far, I still don't understand the meaning of standby data flow ? The English name is alternate data streams.
3.6 find and findstr All commands support exit codes ( Error code )
find and findstr The exit code of the command is 3 Kind of , Each represents different search results .
Exit code | explain |
---|---|
0 | Find the search string |
1 | The search string cannot be found |
2 | The file searched cannot be found or an invalid command line switch is specified |
findstr command
find command
边栏推荐
- [user defined type] structure, union, enumeration
- Cross-entrpy Method
- STM32开发资料链接分享
- 【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析
- ZYNQ移植uCOSIII
- Advanced learning of MySQL -- basics -- basic operation of transactions
- Slow database query optimization
- Advanced learning of MySQL -- basics -- multi table query -- external connection
- Data processing of deep learning
- 【JokerのZYNQ7020】AXI_EMC。
猜你喜欢
Learn self 3D representation like ray tracing ego3rt
Dell笔记本周期性闪屏故障
. Bytecode structure of class file
[C language] dynamic address book
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
做微服务研发工程师的一年来的总结
C9高校,博士生一作发Nature!
Attention slam: a visual monocular slam that learns from human attention
stm32F407-------DAC数模转换
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
随机推荐
筑梦数字时代,城链科技战略峰会西安站顺利落幕
Lombok makes ⽤ @data and @builder's pit at the same time. Are you hit?
[daily problem insight] prefix and -- count the number of fertile pyramids in the farm
第五篇,STM32系统定时器和通用定时器编程
OSPF configuration command of Huawei equipment
Hero League | King | cross the line of fire BGM AI score competition sharing
Advantages and disadvantages of code cloning
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
A brief history of deep learning (I)
AI super clear repair resurfaces the light in Huang Jiaju's eyes, Lecun boss's "deep learning" course survival report, beautiful paintings only need one line of code, AI's latest paper | showmeai info
【JokerのZYNQ7020】AXI_ EMC。
【JokerのZYNQ7020】AXI_EMC。
Value Function Approximation
[user defined type] structure, union, enumeration
再聊聊我常用的15个数据源网站
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
在jupyter中实现实时协同是一种什么体验
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Advanced learning of MySQL -- Fundamentals -- four characteristics of transactions
equals()与hashCode()