In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Find users with letters in the middle
[root@node01 ~] # grep "u [[: alpha:]] [[: alpha:]] r" / etc/passwd
Saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
Rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
User1:x:505:505::/home/user1:/bin/bash
User2:x:506:506::/home/user2:/bin/bash
[root@node01 ~] # grep "u [[: alpha:]] [[: alpha:]] r" / etc/passwd
Saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
Rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
User1:x:505:505::/home/user1:/bin/bash
User2:x:506:506::/home/user2:/bin/bash
[root@node01 ~] #
Basic regular expression metacharacters:
Character matching:
.: match any single character
[]: matches any single character within the specified range
[^]: matches any single character outside the specified range
[: digit:] 、 [: lower:] 、 [: upper:] 、 [: alpha:] 、 [: punct:] 、 [: space:]
Number of matches: used after the characters you want to specify the number of times they appear, to limit the number of times the characters precede them; default works in greedy mode
*: match the characters in front of them any number of times; 0 ~ 1, multiple times
For example: grep "xfanty"
Abxy
Aby
Xxxxxy
Yab
. *: matches any character of any length
\?: match the character before it 0 times or once; that is, the character before it is optional
\ +: match the character before it one or more times; that is, the character before it must appear at least once
\ {m\}: match the previous character m times
\ {mdirection n\}: match the characters preceding them at least m times and n times at most
\ {0magnetic n\}: match n times at most
\ {m,\}: at least m times
Position Anchor:
^: anchor at the beginning of the line; used for the leftmost side of the pattern
$: anchor at the end of the line; for the rightmost side of the pattern
^ word$: matches the whole row with word
^ $: blank line
^ [[: space:]] * $: indicates that only blank lines can appear, and space can appear any number of times, regardless of whether there is a blank line or not
That is, blank lines or lines containing blank characters
Words: consecutive characters (strings) of non-special character ancestral books are called words
\ or\ b: suffix anchoring for the right side of the word pattern
\: match the complete word exactly
\: precisely anchor words
\ anchor word on the right
Grouping and citation
\ (\): bind one or more characters together and treat them as a whole
\ (xy\) * ab: treat xy as a whole
Tip: the content matched by the pattern in the grouping parentheses is automatically recorded by the regular expression engine with internal variables, which are:
\ 1: the characters matched by the pattern between the left parenthesis, the first left parenthesis and the matching right parenthesis
\ 2: the characters matched by the pattern between the left parenthesis, the second left parenthesis and the matching right parenthesis
\ 3: the characters matched by the pattern between the left parenthesis, the third left parenthesis and the matching right parenthesis
The character channeling of r.. t appears at the beginning of the line and in the middle of the line, that is, the backward reference of grep; refers to the character matched by the pattern in the preceding grouping parenthesis
[root@node01 ~] # grep "^\ (r.. t\). *\ 1" / etc/passwd
Root:x:0:0:root:/root:/bin/bash
[root@node01 ~] #
Egrep:
Regular expression implementation that supports extensions is similar to grep text filtering: grep-E
Generate patches
Diff oldfile newfile > patchfile
-u: use the unfiled mechanism, which displays the context of the file to be modified. The default is 3 lines.
Patch: patching files
Path [option]-i patchfile oldfile
Or
Patch oldfile < patchfile
For examples of grep and egrep usage:
Grep:
Format: grep [option] pattern filename Note: if pattern is an expression or more than two words, it needs to be quoted. Can be single quotation marks or double quotation marks The difference is that single quotation marks cannot refer to variables while double quotes can. GREP'\ 'file line grep' Tom savage' file contains Tom savage line grep'^ Tommy' file contains line grep'\ .bak $'file that begins with Tommy, line grep' [Pp] yramid' file contains words that end with .bak, line grep'[Amurz] 'file contains at least one uppercase letter grep' [0-9] The line 'file contains at least one number grep' [Amurz]... [0-9] 'file contains five characters A line that begins with an uppercase and ends with a number. Grep-w'[tT] est' file contains words and test. Grep-s' ken sun' file finds the line containing ken sun, but does not print the line, but is used to check the exit status. GREP-v aaa file prints lines that do not contain aaa. Grep-i cathy file prints all lines that contain cathy Regardless of the size. GREP-l 'dear cathy' * prints a list of file names containing dear cathy. GREP-n tom file prints matching lines and appends lines with variable numbers. GREP "$LOGNAME" file contains variable contents, note that double quotes must be used, and single quotation marks cannot refer to the variable .GREP' $name' file prints lines containing the character $name.
Egrep:
Egrep = grep-E can use not only basic regular expressions, but also extended expressions. Pay attention to the difference. Extension expression: + matches one or more previous characters, at least one previous character.? Match 0 or more previous characters. A | b | c matches an or b or c () character groups, such as: love (able | ers) matches loveable or lovers. (..)\ 1\ 2 template match. \ 1 represents the previous first template,\ 2 the number of characters in the template in the second parenthesis is between m and n. Egrep'^ + 'file begins with one or more spaces. Grep' ^ * 'file' (TOM | DAN) SAVAGE' file contains lines of TOM SAVAGE and DAN SAVAGE. Egrep'(ab) + 'file contains lines of at least one ab. Egrep'x [0-9]? File contains lines of x or x followed by 0 or more digits. Egrep 'fun\. $' * all files with fun. The line at the end. Egrep'[Amurz] + 'file contains at least one uppercase letter. Egrep' [0-9] 'file at least one numeric line. Egrep' [Amurz]... [0-9] 'file has five characters, the first uppercase The last one is the line of numbers. Egrep'[tT] est' file contains lines of the words test or Test. Egrep 'ken sun' file contains lines of ken sun. Egrep-v' marry' file does not contain lines of marry. Egrep-I 'sam' file does not consider the case of sam and contains lines of sam. Egrep-l "dear ken" * A list of all files containing dear ken. Egrep-n tom file contains tom lines. Appending the line number .egrep-s "$name" file to find the variable name $name does not print but displays the exit status. 0 means found. 1 indicates that the expression did not meet the requirements, and 2 indicates that the file was not found.
Under the rule
\ turn off the special definition of subsequent characters, but\ {\} opens its special definition. Any single character * 0 or more has no meaning in BRE when the single character before it appears alone (because there is nothing before it) ^ has meaning at the beginning of the expression in BRE and anywhere in ERE makes sense $ditto It's just that he represents any character in formula brackets at the end of []-in this case, consecutive ex:1-9 1 to 9 ^ means that all meta characters lose their special meaning [] *\. -] this example is a little more particular about the position in [] and-put in []. *\ 1 this means'or ". Do not worry about single quotation marks or double quotation marks first find note: BRE basic regular expression ERE extension regular expression Note: character set ex: [: alpha:] alphabetic characters [: alnum:] numeric characters [: upper:] uppercase [: lower:] lowercase [: space:] spaces (and'\ t') [..] A multi-character sequence is regarded as a unit [= =] equivalent character set. For those with phonetic symbols, a backward reference is required with an ex:\ 1 to indicate the previous reference, that is, () was originally used once, and applied again. Another note is that n represents a maximum of 9 applications from 1 to 9, starting from the left.
Metacharacter description\ marks the next character as a special character, or a literal character, or a backward reference, or an octal escape character. For example, "\ n" matches the character "n". "\" matches a newline character. The sequence "\" matches "\" and "(" matches "(". ^ matches the starting position of the input string. If the Multiline property of the RegExp object is set, ^ also matches the position after "\ n" or "\ r". $matches the end of the input string. If the Multiline property of the RegExp object is set, $also matches the position before "\ n" or "\ r". * matches the previous subexpression zero or more times. For example, zo* can match "z" and "zoo". * is equivalent to {0,}. + matches the previous subexpression one or more times. For example, "zo+" matches "zo" and "zoo", but not "z". + is equivalent to {1,}. ? Matches the previous subexpression zero or once. For example, "do (es)?" Can match "do" in "does" or "does". ? It is equivalent to {0jue 1}. {n} n is a non-negative integer. Match the determined n times. For example, "o {2}" does not match "o" in "Bob", but can match two o in "food". {n,} n is a non-negative integer. Match at least n times. For example, "o {2,}" does not match "o" in "Bob", but does match all o in "foooood". "o {1,}" is equivalent to "o +". "o {0,}" is equivalent to "o *". {n ·m} m} m 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.