In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the ways to remove the repetition of Shell scripts". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Test file
The code is as follows:
[root@bogon ~] # cat > test
Jason
Jason
Jason
Fffff
Jason
Press Ctr + D to save
1. Sort-u
The code is as follows:
[root@bogon] # sort-u test
Fffff
Jason
2 、 uniq
The code is as follows:
[root@bogon ~] # uniq test
Jason
Fffff
Jason
It can be seen that uniq needs to be sorted before it can be duplicated.
3. The combined use of sort, pipeline and uniq
Remove duplicates and retain a duplicate copy of data
The code is as follows:
[root@bogon ~] # sort test | uniq
Fffff
Jason
Remove all duplicate rows (do not keep duplicate rows) and count the number of rows
The code is as follows:
[root@bogon ~] # sort test | uniq-uc
1 fffff
Find all duplicate rows and count the number of rows
The code is as follows:
[root@bogon ~] # sort test | uniq-dc
4 jason
To repeat according to a certain field
Change the original data to
The code is as follows:
[root@bogon ~] # more test
Jason 1
Jason 2
Jason 1
Fffff 2
Jason 3
[root@bogon] # sort-k 1 test 1-u
Fffff 2
Jason 1
Man sort looks at the usage of sort. The-k parameter is described as follows:
The code is as follows:
-k,-- key=POS1 [, POS2]
Start a key at POS1 (origin 1), end it at POS2 (default end of line)
This is the end of the content of "what are the ways to duplicate Shell scripts". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.