In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about what's different about the regular expression BREs,EREs,PREs in linux's shell. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Regular expression classification:
1. Basic regular expressions (Basic Regular Expression, also known as Basic RegEx or BREs)
2. Extended regular expressions (Extended Regular Expression, also known as Extended RegEx or EREs)
3. The regular expression of Perl (Perl Regular Expression is also called Perl RegEx for short PREs)
Note: only by mastering regular expressions, can you fully master the usage of common text tools under Linux (such as grep, egrep, GUN sed, Awk, etc.).
2. The relationship between common text tools and regular expressions in Linux.
It is very helpful for us to better use regular expressions by grasping the characteristics of several common text tools under Linux.
Grep, egrep regular expression features:
1) grep supports: BREs, EREs, PREs regular expressions
If you do not follow any parameters after the grep instruction, you want to use "BREs".
The grep instruction followed by the "- E" parameter indicates that "EREs" is to be used.
The grep instruction is followed by the "- P" parameter, indicating that "PREs" is to be used
2) egrep supports: EREs, PREs regular expressions
If you do not follow any parameters after the egrep instruction, you want to use "EREs".
The egrep instruction is followed by the "- P" parameter, indicating that "PREs" is to be used
3) grep and egrep regular matching file, processing file method
A. dealing with grep and egrep: text files
B. the process of grep and egrep: find out whether the text file contains a "keyword" (the keyword can be a regular expression). If it contains a "key word" to find, the contents of the line containing the "key word" in the text file are returned by default and displayed in standard output, unless the ">" redirection symbol is used.
C. grep and egrep handle text files on a line-by-line basis
Characteristics of sed regular expression
1) sed text tool support: BREs, EREs
The sed instruction defaults to using "BREs"
The sed command argument "- r" indicates that you want to use "EREs"
2) the function and function of sed
A. objects processed by sed: text files
B. sed processing operation: search, replace, delete, add and other operations on the contents of the text file
C. Sed also processes text files on a line-by-line basis
Characteristics of Awk (gawk) regular expression
The code is as follows:
1) Awk text tool support: EREs
The awk instruction defaults to using "EREs"
2) the characteristics of Awk text tool in dealing with text.
A. objects processed by awk: text files
B. awk processing operations: mainly operate on columns
3. Comparison of types of regular expressions in common 3
The character indicates that the Basic RegExExtended RegExpython RegExPerl regEx escape\ ^ matches the beginning of the line, for example,'^ dog' matches a line that begins with the string dog (Note: in the awk instruction,'^'is the beginning of the matching string) ^ $matches the end of the line, for example:'^, dog$' matches the line ending with the string dog (Note: in the awk instruction,'$'is the end of the matching string) $$
^ $
Match blank lines
^ $^ string$ matches lines, for example:'^ dog$' matches lines with only one string dog ^ string$ ^ string $^ string $^ string $\\ > not supported (but words can be matched using\ b, for example: 'frog\ b')
\
Match a word or a specific character, for example:'\'(equivalent to'\ bfrog\ b'),'\'\\ is not supported (but you can use\ b to match a word, for example:'\ bfrog\ b'
()
Matching expressions, for example:'(frog)'is not supported (but you can use\ (\), such as:\ (dog\) ()
\ (\)
Matching expression, for example:'(frog)'\ (\) is not supported (same as ())
?
Match the previous subexpression 0 or 1 times (equivalent to {0jue 1}), for example: where (is)? Can match "where" and "whereis" is not supported. \? Match the previous subexpression 0 or 1 times (equivalent to 'where\ (is\) 1\}'), for example: can match "where" and "whereis"\? Not supported (same as?) Not supported (same as?) Not supported (with?)? When the character is immediately followed by any other qualifier (*, +,?, {n}, {n,}, {n ·m}), the matching pattern is not greedy. The non-greedy pattern matches the searched string as little as possible, while the default greedy pattern matches the searched string as much as possible. For example, for the string "oooo", 'oiled eggs' Will match a single "o", while 'okeeper' will match all'o' unsupported. Match any single character except the newline character ('\ n'). (note: periods in the awk instruction can match newline characters). (if you want to match any character including "\ n", use:'(^ $) | (.). (if you want to match any character including "\ n" Please use: [.\ n]'* to match the previous subexpression 0 or more times (equivalent to {0,}), for example: zo* can match "z" and "zoo" *\ + match the previous subexpression one or more times (equivalent to'\ {1,\}') For example: 'where\ (is\)\ +' can match "whereis" and "whereisis"\ + does not support (with +) + to match the previous subexpression one or more times (equivalent to {1,}). For example, zo+ can match "zo" and "zoo", but cannot match "z" does not support (same as\ +) +
{n}
N must be a 0 or positive integer, matching subexpression n times, for example: zo {2} can match (same as\ {n\}) {n} {n,} "zooz", but cannot match "Bob" n must be a 0 or positive integer, matching subexpression greater than or equal to n times For example, go {2,} does not support (with\ {n,\}) {n,} {n,} {n ~ (n),} {n ~ (th) m} can match "good", but can not match that godm and n are non-negative integers, where n
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.