In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the advanced use of Linux grep". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "the advanced use of Linux grep".
1. Basic regular expression exercise
Required documents
Wget http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt
Search for specific characters
Isn't it easy to search for specific strings? Suppose we want to get the specific string the from the file just now. The simplest formula is this:
Grep-n 'the' filename
Plus-n displays the file line number and is case-sensitive.
A case-insensitive search will find that there are several more lines than above, because all the lines are displayed without case sensitivity
Use brackets [] to search for characters
If I want to search for the words test or taste, I can find that they have a common 'tactist'. At this time, I can search like this.
Grep-n't [EA] st' filename
In fact, no matter how many characters there are in [], he only represents a "one" character, so the above example shows that the string I need is a "tast" or "test" string! If you want to find a character with oo, use:
But what if I don't want g in front of oo? At this point, you can use the reverse selection of the collection characters to achieve the meaning, that is, what I need is oo, but it can't be preceded by g before oo! If you carefully compare the above two tables, you will find that line 1, oo 9 is missing, because g appears in front of the table! There is no doubt on line 2 and 3, because both foo and Foo are acceptable! But line 18 clearly has the goo of google ~ Don't forget, because there is the too of tool behind the line! So the line is also listed ~ that is to say, although there are items we don't want (goo) in the 18 lines, because there are needed items (too), it is consistent with string search! As for line 19, again, because the oo in goooooogle may be preceded by o, for example: go (ooo) oogle, this line also meets the requirements
Remove the lowercase in front of the oo
Take out the lines with numbers
Take out the line that begins with the
Take out lines that begin with lowercase letters
Take out the lines that do not want to start with letters
two。 Pay attention: have you noticed? That ^ symbol is different inside and outside the character set symbol (parenthesis [])! It stands for "reverse selection" in [] and the meaning of positioning at the beginning of the line outside []! To make a clear distinction, it is written here to stand out,
Take out the trailing point
The decimal point has other meanings, so you must use the skip character (\) to remove its special meaning!
Take out a blank line
We need to find out the string of Groupd.
Want to find the string that begins with g and ends with g
But there are so many lines in the test results? Isn't that weird? In fact, it's not weird at all, because the g generation table in gg is "empty character or more than one g" followed by g, so the content of the whole RE is g, gg, ggg, gggg, so as long as there is more than one g in the line.
So how do we get our g. G demand? He he! Just use any character "." Aah! That is, the construction of "g.g", because it can be 0 or more repeats the previous characters, and. It's any character, so ". * represents zero or more arbitrary characters"!
13. To find out the ranks of "arbitrary numbers"
14.
3. Case
When we search for configuration files, it's quite painful, because there are a lot of configuration files that start with #, but we don't need them, so let's solve this problem.
Search for things that don't start with #
When there are spaces in the file, it is also possible to remove spaces.
Thank you for your reading, the above is the content of "Advanced use of Linux grep", after the study of this article, I believe you have a deeper understanding of the advanced use of Linux grep, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.