In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to quickly get started with Linux's uniq commands. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The Linux uniq command is used to check and delete repeated rows in a text file. Uniq checks for recurring rows in a text file.
Format uniq [options] [file]
Option description:
-cmam talk delimit-method count: show the number of occurrences of lines-dmy talk repeated: only display repeated lines, that is, lines whose occurrence times are > = 2, and print only once-Dmam show repeated lines, that is, lines with the number of occurrences > = 2, and print all lines of duplicate lines. Where delimit-method represents the way to separate a set of duplicate rows, and there are three values, namely none, prepend, and separate. Where none means no separation, which is the default option, uniq-D is equivalent to uniq-all-repeated=none;prepend means to insert a blank row before each duplicate row set, and separate means to insert a blank row between each duplicate row set. -freguency: ignore the first N fields. Fields are separated by white space characters (space, Tab). If the lines of your document are numbered, and you want to compare everything in the line except the line number. If the option-f 1 is specified, then the following two adjacent lines: 1 this is a line. This is a line. Will be considered the same. If the-f option is not specified, they are considered unique. -imam quotient: ignore the difference between uppercase and lowercase characters-help: skip the first N characters and do not compare-umai unique: show only the unique line, that is, the line whose number of occurrences is equal to 1-WQ QQ check the number of chars for each line: specify the number of first N characters to be compared per line-- help: display help information-- version: display version information common examples
(1) it is invalid to remove duplicates from unordered files. The testfile is as follows:
Cat testfilehelloworldfriendhelloworldhello
Delete unsorted files directly and you will find that no lines have been deleted:
# uniq testfile helloworldfriendhelloworldhello
(2) uniq combines the sort command to remove the duplicates of the sorted files.
# cat testfile | sort | uniqfriendhelloworld
(3) the duplicate rows are deleted after sorting, and the number of repetitions of the row is output at the beginning of the line.
# sort testfile | uniq-C1 friend3 hello2 world
(4) only rows with duplicates are displayed, and the number of times the line is repeated at the beginning of the line:
# sort testfile | uniq-dc3 hello2 world
(5) only rows that do not repeat are displayed.
Sort testfile | uniq-ufriend
(6) only duplicate rows are displayed, and all rows of duplicate rows are displayed.
Sort testfile | uniq-Dhellohellohelloworldworld
(7) uniq defaults to compare all the contents of adjacent lines to determine whether to repeat or not. We can specify to compare the first N characters with the option-w or-- check-chars=N. For example, we have a file test.txt with the following contents:
Appleapplicationapi
Print lines with the same first three characters:
Uniq-w3-D test.txtappleapplication
Thank you for reading! This is the end of this article on "how to get started with the uniq command of Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.