In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to use substr in awk. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
String function substr of awk
Substr (sjournal p) returns the suffix part of the string s that begins with p
Substr returns the suffix part of the string s whose length is n starting from p
Instance operation
$awk'$1pm = "L.Transley" {print substr ($1,1jue 5)} 'grade.txt
L.Tan
In the above example, you specify that the first character in field 1 starts and returns the first five characters.
If the given length value is much greater than the string length, awk returns all characters from the starting position, and to extract the last name of L.Tansley, you only need to return a length of 7 from the third character. The same result can be returned by the input length 99 ~ (th) awk.
$awk'{$1 million = "L.Transley" {print substr ($1,39,99)} 'grade.txt
Transley
Another form of substr is to return a string suffix or a character after a specified position. Here you need to give the specified string and the starting position of the returned string. For example, to extract a last name from a text file, you need to manipulate field 1, starting with the third character:
$awk'{print substr ($1,3)} 'grade.txt
Troll
Transley
Another example is to define a string in the BEGIN section and return a substring extracted from the t-th character in the END section.
$awk'{BEGIN STR= "A FEW GOOD MEN"} END {print substr (STR,7)) grade.txt
GOOD MEN coach
The above is how to use substr in awk. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow 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.
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.