In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "grep command introduction in Linux". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
The three most important commands in Linux are known in the industry as the Three Musketeers: awk, sed, and grep. sed was covered in the previous article, and this article is about the grep command.
We use Linux system, grep command is particularly frequent, familiar with the common use of grep, can greatly improve your work efficiency.
The grep command is a powerful text search tool that uses regular expressions to match specified patterns and print out matching lines. Note that grep only supports matching and cannot replace matching content, which can be done by sed.
Grep is still relatively simple on the whole, this article will not list all the options and parameters in detail, will use a number of specific examples to illustrate the use of grep methods and scenarios, to help you quickly learn the common use of grep.
Examples of actual combat
Let's not talk nonsense, let's go straight to actual combat. The example in this article requires a sample file that reads as follows:
1. Filter out lines containing syslog
2. Filter out lines starting with ntp
3. Filter out the rows matching ntp and the two rows below
4. Filter out the line containing syslog and above
5. Filter out the contents of syslog and the lines above and below
6. Filter a keyword and output the line number
7. Filter does not contain a keyword, and output line number
8. Delete blank lines
9. Filter lines containing root or syslog
10. View all files in the current directory that contain a keyword (useful)
simple summary
Through some simple case operations, we should have been familiar with the common use of grep, below to briefly summarize the common options of grep, I believe that after the actual practice to summarize should have a better learning effect.
-A: In addition to the matching row, N rows after the row are additionally displayed.
-B: In addition to the matching row, the N rows before the row are additionally displayed.
-C: In addition to the matching row, N rows before and after the row are additionally displayed
-c: Counts the number of rows matched
-e: Implement logical or relationships between multiple options
-E: Support extended regular expressions
-F: equivalent to fgrep
-i: ignore case
-n: Display matching row numbers
-o: Display only matched strings
-q: Quiet mode, no output, common in scripts
-s: No error message displayed
-v: Display rows that are not matched
-w: Display the whole word
--color: Highlight matched strings in color
Tools similar to grep are egrep and fgrep, which are not practical, and their functions can be fully implemented through grep's extended parameters, so they will not be extended.
"Linux grep command introduction" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.