In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Linux grep command specific use method is what, I believe that many inexperienced people are helpless, for this reason this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The Linux grep command is used to find strings in a file that match the criteria. The grep command is used to find files whose contents contain the specified template style. If the contents of a file match the specified template style, the grep command will display the column containing the template style by default.
grep [-abcEFGhHilLnqrsvVwxy][-A][-B][-C][-d][-e][--help][template style][file or directory...] Parameters:
-a or-text : Do not ignore binary data.
-A or-after-context= : Displays the content after that row, except for the column that matches the template style.
-b or-byte-offset : Mark the number of the first character of the line before displaying the line that matches the style.
-B or-before-context= : Display the content before the line except for the line that matches the style.
-c or-count : Counts the number of columns that match the style.
-C or-context= or- : Displays the line before and after the line except for the line that matches the style.
-d or-directories= : This parameter must be used when specifying directories rather than files, otherwise the grep directive returns information and stops the action.
-e or-regexp= : Specifies a string as a style to find the contents of a file.
-E or-extended-regexp : Use regular expressions whose style is extended.
-f or-file= : Specifies a rule file whose contents contain one or more rule styles, allowing grep to find file contents that match the rule criteria, formatted as one rule style per line.
-F or-fixed-regexp : treats styles as lists of fixed strings.
-G or-basic-regexp : Use styles as if they were normal notation.
-h or-no-filename : Does not indicate the file name to which the line belongs until the line that matches the style is displayed.
-H or-with-filename : Indicates the file name to which the line belongs before displaying the line that matches the style.
-i or-ignore-case : Ignore case differences.
-l or-file-with-matches : Lists file names whose content matches the specified style.
-L or-files-without-match : Lists file names whose content does not conform to the specified style.
-n or-line-number : Mark the column number of the row before displaying the row that matches the style.
-o or-only-matching : Show only matching PATTERN parts.
-q or-quiet or-silent : No information is displayed.
-r or-recurrent: This parameter has the same effect as specifying the "-d recurrent" parameter.
-s or-no-messages : No error messages are displayed.
-v or-invert-match : Displays all lines that do not contain matching text.
-V or-version : Displays version information.
-w or-word-regexp : Displays only columns that match all words.
-x-line-regexp : Show only columns that match all columns.
-y : This parameter has the same effect as specifying the "-i" parameter.
grep supports basic regular expressions: Basic regular expressions
grep -E also supports extended regular expressions: extended regular expressions
grep supported characters [:digit:]: all digits, equivalent to 0-9 or\d
[:lower:]: all lowercase letters
[:upper:]: all capital letters
[:alpha:]: all letters
[:alnum:]: Equivalent to [0-9a-zA-Z]
[:space:]: Blank character, equivalent to\s
[:punct:]: All punctuation marks
grep -E or egrep supported characters\s: matches any white space character, including spaces, tabs, form breaks, etc., equivalent to [ \f\n\r\t\v ]
\S: Matches any non-white space character, equivalent to [ ^\f\n\r\t\v ]
\w: Matches any literal character, including underscore, equivalent to [A-Za-z0 -9_]
\W: Matches any non-word character, equivalent to [ ^A-Za-z0 -9_]
grep -P supported characters\d: numeric character match, equivalent to [0-9]
example
1. Match a line in eg.text that starts with a #and is followed by at least one white space character followed by any non-white space character grep "^#[[:space:]]\{1,\}[^[:space:]]" eg.text Unpack grep "^# [[:space:]] \{1,\} [^[:space:]]" eg.text grep -E "^#\s\{1,\}\S" eg.text Unpack grep -E "^# \s \{1,\} \S" eg.text 2, Match eg.text with a line containing: grep ":[:digit: ]:" eg.text Unpack grep ":[: digit:] :" eg.text grep -P ":\d:" eg.text Unpack grep-P ":\d:" eg.text
Examples of grouping
grep "l.. e.* l.. er" test.txt grep "\(l.. e\).*\ 1r" test.txt
Match numbers 1-255
grep -E "\" num.txt
Match Email Address: Any Length Numeric Letter @ Any Length Numeric Letter
grep -E "^\w+([-+.]\ w+)*@\w+([-.]\ w+)*\.\ w+([-.]\ w+)*$" email.txt
Match cell phone number, put cell phone number is 1[3| 4| 5| 8] followed by 9 digits filtered out
grep -E "\" tel.txt
After reading the above, do you know how to use Linux grep command? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
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.