In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Grep command:
Template:
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
P.Bunny 02/99 48 Yellow 12 35 2658
J.Troll 07/99 4842 Brown-3 12 26 266666
L.Tansley 05/99 4712 Brown-2 12 30 44544
Single and double quotation marks:
Single quotation marks are required when matching patterns.
In the matching string ("123 ABC"), the grep command will treat ABC as a file without double quotation marks. ) and variables need to be in double quotes
Grep allows the use of international character pattern matching or the form of class names that match patterns.
Class name and its equivalent regular expression
Regular expressions of class equivalence
[[: u p p e r:]] [A-Z]
[[: a l n u m:]] [0-9 a-zA-Z]
[[: l o w e r:]] [a-z]
[[: s p a c e:]] spaces or t a b key
[[: d i g i t:]] [0-9]
[[: a l p h a:]] [a-z A-Z]
Parameters:
-c: count the number of matching patterns.
Example: [root@localhost GREP] # grep-c Green data.f
one
-I: case-insensitive.
Example: [root@localhost GREP] # grep-I green data.f
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
[root@localhost GREP] # grep "[Gg] reen" data.f explanation: you can also use range patterns to match, or single quotation marks.
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
-h: matches the pattern in multiple files, ignoring the file name.
Example: [root@localhost GREP] # grep green data.f data.f.bak
Data.f:J.Lulu 06/99 48317 green 9 24 2678.
Data.f.bak:J.Lulu 06/99 48317 green 9 24 2678.
[root@localhost GREP] # grep-h green data.f data.f.bak
J.Lulu 06/99 48317 green 9 24 2678.
J.Lulu 06/99 48317 green 9 24 2678.
-l: displays the file where the matching pattern is located.
Example: [root@localhost GREP] # grep-l green data.f data.f.bak
Data.f
Data.f.bak
[root@localhost GREP] # grep-l green * explanation: "*" to find all files in the current directory can also be used as "*. Suffix name" to match it.
Data.f
Data.f.bak
-n: displays the line number of the matching pattern.
Example: [root@localhost GREP] # grep-n green data.f
2:J.Lulu 06/99 48317 green 9 24 2678.
-s: ignore the information returned because the file does not exist.
Example: [root@localhost GREP] # grep green ABC explanation: there are no ABC files in this directory, so an error message is returned. The error message is ignored when the-s parameter is added.
Grep: ABC: there is no such file or directory
[root@localhost GREP] # grep-s green ABC
[root@localhost GREP] # echo $?
two
-v: reverse search for information.
Example: [root@localhost GREP] # cat data.f.bak explanation: replace the pattern to be matched with variables.
Green
Yellow
[root@localhost GREP] # AAA= `cat data.f.bak`
[root@localhost GREP] # echo $AAA
Green Yellow
[root@localhost GREP] # grep-v "$AAA" data.f
M.Tansley 05/99 48311 Green 8 40 44.44
J.Troll 07/99 4842 Brown-3 12 26 266666
L.Tansley 05/99 4712 Brown-2 12 30 44544
Exact match:
Example: [root@localhost GREP] # grep "48\ >" data.f
P.Bunny 02/99 48 Yellow 12 35 2658
Range match:
Example: [root@localhost GREP] # grep "48 [34]" data.f interpretation: "[]" can be used to specify a string range.
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
J.Troll 07/99 4842 Brown-3 12 26 266666
Whether to match the beginning of the line:
Example: [root@localhost GREP] # grep "^ [^ J]" data.f interpretation: if you want to extract a line that does not start with 48, you can use the ^ token in square brackets to indicate that the query begins at the beginning of the line.
M.Tansley 05/99 48311 Green 8 40 44.44
P.Bunny 02/99 48 Yellow 12 35 2658
L.Tansley 05/99 4712 Brown-2 12 30 44544
Example: [root@localhost GREP] # grep "^ J" data.f interpretation: "^" use this symbol if it starts with something.
J.Lulu 06/99 48317 green 9 24 2678.
J.Troll 07/99 4842 Brown-3 12 26 266666
Any match:
Example: [root@localhost GREP] # grep "B.2" data.f interpretation: "." The dot represents an arbitrary number. "*" stands for any number of digits.
The L.Tansley 05Accord 99 4712 Brown-2 12 30 44544 sample indicates that the beginning of B has 2 endings and the beginning of B has an arbitrary number of endings.
[root@localhost GREP] # grep "B. [1-9]" data.f
J.Troll 07/99 4842 Brown-3 12 26 266666
L.Tansley 05/99 4712 Brown-2 12 30 44544
[root@localhost GREP] # grep "J. [a-z Magi Amurz] [a Mizz Magi Amurz]" data.f interpretation:
J.Lulu 06/99 48317 green 9 24 2678.
J.Troll 07/99 4842 Brown-3 12 26 266666
[root@localhost GREP] # grep "[Amurzjour Amurz] .ll" data.f is delimited by a comma
J.Troll 07/99 4842 Brown-3 12 26 266666
Pattern location lookup:
For example: [root@localhost GREP] # grep'[Amurz Magi Amurz]\ {5\} [w] 'data.f explanation: look for a pattern with 5 letters (Amurz and Amurz) and end with w, because this is a matching pattern, use single quotation marks
P.Bunny 02/99 48 Yellow 12 35 2658
Pattern random search:
Example: [root@localhost GREP] # grep'2\ {1pr 6\} 6' data.f explanation: look in the file for the number 2 that is repeated six times and the number ends with six (26,226,2226 and so on).
J.Lulu 06/99 48317 green 9 24 2678.
P.Bunny 02/99 48 Yellow 12 35 2658
J.Troll 07/99 4842 Brown-3 12 26 266666
Example: [root@localhost GREP] # grep'4\ {1Jing 10\} 7' data.f
L.Tansley 05/99 4712 Brown-2 12 30 44544
Range combination:
Example: [root@localhost GREP] # grep "^ [Amurz]. [AB]. *" data.f interpretation: [Amurz] represents any letter after the letter "." The dot represents any character, and [AB] represents only two letters An and B, followed by ". *" any number of digits.
P.Bunny 02/99 48 Yellow 12 35 2658
Blank line and change of mind:
Example: [root@localhost GREP] # grep'^ $'data.f
Example: [root@localhost GREP] # grep'J\ .Troll 'data.f interpretation: query characters with special meaning, precede specific characters with "\"
J.Troll 07/99 4842 Brown-3 12 26 266666
Grep-E parameters:
For example: [root@localhost GREP] # grep-E-- color=auto'[Amurz Zgramma] reen | [Amurz] ellow' data.f explanation: egrep is an extended usage of grep. The increment is to match the pattern.-- color=auto adds color to the matching pattern.
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
P.Bunny 02/99 48 Yellow 12 35 2658
[root@localhost GREP] # grep-- color=auto'[Amurz Zjuramurz] reen\ | [Amurz] ellow' data.f explanation: adding a change of mind before the vertical bar can also achieve the purpose of egrep.
M.Tansley 05/99 48311 Green 8 40 44.44
J.Lulu 06/99 48317 green 9 24 2678.
P.Bunny 02/99 48 Yellow 12 35 2658
Class name and its equivalent regular expression:
Example: [root@localhost GREP] # grep'[[: upper:]] reen' data.f
M.Tansley 05/99 48311 Green 8 40 44.44
Example: [root@localhost GREP] # grep'J\. [[: upper:]] 'data.f
J.Lulu 06/99 48317 green 9 24 2678.
J.Troll 07/99 4842 Brown-3 12 26 266666
Egrep-f parameter usage:
Example: [root@localhost GREP] # cat data.f.bak
Green
Yellow
266666
[root@localhost GREP] # egrep-f data.f.bak data.f explanation: egrep can use the string saved in the document as its own parameter and turn on the function with-f.
J.Lulu 06/99 48317 green 9 24 2678.
P.Bunny 02/99 48 Yellow 12 35 2658
J.Troll 07/99 4842 Brown-3 12 26 266666
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.