In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use the regular expression findstr in batch processing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Grammar
Findstr [/ b] [/ e] [/ l] [/ r] [/ s] [/ i] [/ x] [/ v] [/ n] [/ m] [/ o] [/ p] [/ offline] [/ g:File] [/ f:File] [/ c:String] [/ d:DirList] [/ a:ColorAttribute] [Strings] [[Drive:] [Path] FileName [...]]
Parameters.
/ b
Matches the pattern if it is at the beginning of the line.
/ e
Matches the pattern if it is at the end of the line.
/ l
Search for strings word for word.
/ r
Use the search string as a regular expression. Findstr interprets all metacharacters as regular expressions unless / l is used.
/ s
Search the current directory and all subdirectories for matching files.
/ i
Specifies that the search is case-insensitive.
/ x
Print lines that match exactly.
/ v
Only print lines that do not match.
/ n
Print the line number before each matching line.
/ m
If the file contains a match, only that file name is printed.
/ o
Prints the lookup offset before each matching line.
/ p
Skip files that contain non-printable characters.
/ offline
Use offline property settings to process files.
/ f:File
Reads a list of files from the specified file.
/ c:String
Uses the specified text as the text search string.
/ g:File
Gets the search string from the specified file.
/ d:DirList
Search for a comma-separated list of directories.
/ a:ColorAttribute
Use two hexadecimal numbers to specify the color attribute.
Strings
Specifies the text to search in FileName.
[Drive:] [Path] FileName [...]
Specify the files to search for.
/?
Displays help at the command prompt.
Annotation
Use Strings and [Drive:] [Path] FileName [...]
In the command string, all findstr command line options must be in Strings and [Drive:] [Path] FileName [...] Before.
Using regular expressions in findstr
Findstr can find the exact text you are looking for in any ASCII file or file. However, sometimes there is only part of the information to match or to find a broader range of information. In this case, findstr has the powerful ability to search for a variety of text using regular expressions.
A regular expression is a symbol used to specify a text type, as opposed to an exact string. Tags use text characters and metacharacters. Every character that has no special meaning in regular expression syntax is a literal character that matches the character that appears. For example, letters and numbers are literal symbols. Metacharacters are symbols that have a special meaning (operator or delimiter) in regular expression syntax.
The following table lists the metacharacters accepted by findstr.
Character value
.
Wildcards: any character
*
Repetition: a character or class that appears zero or more times before.
^
Position in line: beginning of Lin
$
Position in line: end of line
[class]
Character class: any character in the set
[^ class]
Reverse class: any character in a non-set
[Xmury]
Range: any character within the specified range
\ X
Escape: the textual use of metacharacter X
\ position of the word: prefix
Xyz\ >
Position of the word: suffix
Special characters that combine regular expression syntax are very powerful. For example, the following wildcard character (.) The combination of and repeating character (*) can match any string:
. *
Use the following expression as part of a larger expression that matches any string that starts with "b" and ends with "ing":
B.*ing
Example
Separate multiple search strings with spaces, unless the parameter is prefixed with / c. To search for "hello" or "there" in the file x.y, type:
Findstr "hello there" x.y
To search for "hello there" in the file x.y, type:
Findstr / c: "hello there" x.y
To find all the words "Windows" (with the first letter W capitalized) that appear in the file Proposal.txt, type:
Findstr Windows proposal.txt
To search for each file in the current directory and all subdirectories that contain the word Windows, regardless of letter case, type:
Findstr / s / I Windows *. *
To find all lines that contain the word "FOR" (preceded by any space, such as a loop in a computer program), and include the line number that appears each time, type:
Findstr / b / n / c: "* FOR" * .bas
If you want to search for several different items in the same group of files, create a text file on the new line that contains each search criteria. You can also list the exact files to search for in text files. To use the search criteria in the file Finddata.txt to search for the files listed in Filelist.txt, and then save the results to the file Results.out, type:
Findstr / g:finddata.txt / f:filelist.txt > results.out
Suppose you want to find every file that contains the word "computer" in the current directory and all subdirectories, regardless of the case of letters. To list all files that contain the word "computer", type:
Findstr / s / I / m "\" *. *
Now suppose you need to look not only for the word "computer", but also for all other words that start with the letter "comp", such as "compliment" and "compete". Please type:
Findstr / s / I / m "\
Http://www.microsoft.com/technet/prodtechnol/windowsserver2003/zh-chs/library/ServerHelp/2b01d7f5-ab5a-407f-b5ec-f46248289db9.mspx?mfr=true
Example:
1.findstr. 2.txt or findstr "." 2.txt
Find any character from the file 2.txt, excluding empty characters or blank lines
=
2.findstr. * 2.txt or findstr ". *" 2.txt
Find any characters, including blank lines and empty characters, from the file 2.txt
=
3.findstr "[0-9]" 2.txt
Look for a string or line that includes the number 0mur9 from the file 2.txt
=
4.findstr "[a-zA-Z]" 2.txt
Find a string or line that includes any character from the file 2.txt
=
5.findstr "[abcezy]" 2.txt
Find a string or line that includes the a b c e z y letter from the file 2.txt
=
6.findstr "[a-fl-z]" 2.txt
Look for the string for the lowercase character amurf lmerz from the file 2.txt, but does not contain the letters g h I j k.
=
7.findstr "M [abc] [hig] Y" 2.txt
From the file 2.txt, you can match MahY, MbiY, MahY, etc. ..
=
8. Application of ^ and $symbols
^ indicates the beginning of the line, and "^ step" matches only the first word in "step hello world"
$indicates the end of the line, and "step$" matches only the last word in "hello world step"
=
9.finstr "[^ 0-9]" 2.txt
If it is a pure numeric string or line, it will be filtered out, such as 2323423423, but not in the form of 345hh888.
=
10.findstr "[^ a Merz]" 2.txt
As above, if it is a pure letter string or line, it will be filtered out. For example, a character such as sdlfjlkjlksjdklfjlskdf will not be mixed with numbers if it is in the form of sdfksjdkf99999.
=
The role of number 11.*
As mentioned earlier, ". *" indicates that the search condition is any character, and the role of the * sign in a regular expression is not any character, but the number of repetitions of the left character or expression, and the * sign indicates zero or more repetitions.
=
12.findstr "^ [0-9] * $" 2.txt
This is the pure number found by the match, such as 234234234234, which is filtered out if it is 2133234kkjl234.
Findstr "^ [a Merz] * $" 2.txt
This is the pure letter found by the match, such as sdfsdfsdfsdf. If it is 213sldjfkljsdlk, it will be filtered out.
If there is no * sign in the search condition, that is, do not repeat the search condition on the left, that is, [0-9] [a murz], then only one character can match the first character of the string. Because of the restrictions on the beginning and end of the line, the first character of "^ [0-9] $" matches if it is a number, and if not, it is filtered out. If the string is 9, it matches. Not if it's 98 or 9J or something like that.
=
13. The function of the expression "\"
This means to find a string precisely, and\ indicates the end position of the word.
Echo hello world computer | findstr "\"
Echo hello worldcomputer | findstr "\" is not good. He is looking for the string "computer", so it is not allowed.
Echo hello worldcomputer | findstr ". * computer\ >" so it can be matched.
=
Thank you for reading! This is the end of this article on "how to use regular expression findstr in batch processing". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.