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

How to realize text de-duplication and count the number of repetitions in linux

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

Share

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

This article mainly introduces how to achieve text de-duplication and count the number of repetitions in linux, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The linux command line provides very powerful text processing capabilities, and the combination of linux commands can achieve many powerful functions. This article gives an example of how to use the Linux command line to de-duplicate text by line and sort by number of repeats. The main command used is sort,uniq. Among them, the main function of sort is sorting, and the main function of uniq is to remove the duplicates of adjacent text lines.

The test file test.txt for the demonstration is as follows:

Hello World. Apple and Nokia. Hello World. I wanna buy an Apple device. The Iphone of Apple company. Hello World. The Iphone of Apple company. My name is Friendfish. Hello World. Apple and Nokia.

The command is as follows:

$sort test.txt | uniq-c | sort-rn 4 Hello World. 2 The Iphone of Apple company. 2 Apple and Nokia. 1 My name is Friendfish.

The uniq command plus the-c option allows you to count the number of repetitions, and sort-n recognizes the number at the beginning of each line and sorts the lines of text by their size. The default is to sort in ascending order, and add the-r option (sort-rn) if you want to sort in descending order.

Thank you for reading this article carefully. I hope the article "how to remove duplicates in linux and count the number of repetitions" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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