Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the examples of using the grep command

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge points about the use of grep commands, which are detailed in content and clear in logic. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Example actual combat

Cut the crap and go straight to the actual combat. The example in this article requires a sample file with the following contents:

\ 1. Filter out rows that contain syslog

\ 2. Filter out lines that start with ntp

\ 3. Filter out the rows that match ntp and the next two lines

\ 4. Filter out the line containing syslog and above

\ 5. Filter out the contents including syslog, the previous line and the next line

\ 6. Filter a keyword and output the line number

\ 7. Filter does not contain a keyword and output a line number

\ 8. Delete blank lines

\ 9. Filter rows that contain root or syslog

\ 9. Filter rows that contain root or syslog

Simple summary

Through some simple case operations, we should already be familiar with the common usage of grep, and then briefly summarize the common options of grep. I believe that summarizing it after practical practice should have a better learning effect.

-A: in addition to the matching line, the N lines after the line are displayed

-B: display the N lines before the row in addition to the matching row

-C: display the N lines before and after the line in addition to the matching line

-c: count the number of matching rows

-e: implement logical or relationships between multiple options

-E: regular expressions that support extensions

-F: equivalent to fgrep

-I: ignore case

-n: displays the matching line number

-o: only the matching strings are displayed

-Q: quiet mode, does not output any information, commonly used in scripts

-s: no error message is displayed

-v: displays rows that are not matched

-w: displays the entire word color: highlights the matching string in color

And grep similar tools are egrep, fgrep, practical is not strong, its function can be achieved through the extension parameters of grep, so no longer expand.

These are all the contents of the article "what are the examples of the use of the grep command?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report