In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the use of the uniq command in Linux, 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.
Uniq [options] file
Description: this command reads the input file and compares adjacent lines. Under normal circumstances, the second and subsequent duplicate lines are deleted, and line comparisons are made based on the sorted sequence of the character set used. The processed result of the command is written to the output file. Input and output files must be different. If the input file is represented by "-", it is read from standard input.
The options of the command have the following meanings:,
-c displays the number of times the line appears in the file at the beginning of each line. It replaces the-u and-d options.
-d displays only duplicate lines.
-u displays only lines in the file that are not duplicated.
-the first n fields are ignored along with the white space in front of each field. A field is a non-space, non-tab string separated by tabs and spaces (fields are numbered from 0).
The first n characters of + n are ignored and the previous characters are skipped (characters are numbered from 0).
-f n is the same as-n, where n is the number of fields.
-s n is the same as + n, where n is the number of characters.
Next, it is illustrated by practical examples:
=
[root@stu100 ~] # cat testboy took bat homeboy took bat homegirl took bat homeboy took bat homeboy took bat homedog brought hat homedog brought hat homedog brought hat home
Look at the contents of the test file
=
[root@stu100 ~] # uniq testboy took bat homegirl took bat homeboy took bat homedog brought hat home
The uniq command takes no arguments and only displays the lines that are repeated continuously once.
=
[root@stu100 ~] # uniq-c test2 boy took bat home1 girl took bat home2 boy took bat home3 dog brought hat home1
The-c parameter displays the number of consecutive occurrences of each line in the file.
=
[root@stu100 ~] # cat test | sort | uniq-c14 boy took bat home3 dog brought hat home1 girl took bat home
Sort and then display
=
[root@stu100 ~] # uniq-d testboy took bat homeboy took bat homedog brought hat home
The-d option displays only successive recurring lines in the file.
=
[root@stu100 ~] # uniq-u testgirl took bat home
The-u option displays lines that do not appear in succession in the file.
=
[root@stu100] # uniq-f 2-s 2 testboy took bat home
Ignore the first two fields of each line, ignore the second white space character and the first character of the third field, resulting in at home
=
[root@stu100] # uniq-f 1 testboy took bat homedog brought hat home
Omit the * * fields of each line so that the lines that begin with boy, girl appear to be consecutive repeats.
=
[root@stu100 ~] # uniq-D testboy took bat homeboy took bat homeboy took bat homeboy took bat homedog brought hat homedog brought hat homedog brought hat home
Show all duplicate rows, each duplicate row is displayed
Thank you for reading this article carefully. I hope the article "what is the use of uniq commands in Linux" shared by the editor will be helpful to you. 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.
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.