Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Text Uniq is a duplicate line in the Linux command usage report or delete file. Syntax Uniq [-c |-D |-u] [f Fields] [-S Characters] [-fields] [+characters] [InFile [outfile]] Description uniq command Delete file Duplicate rows in the. The Uniq command reads the standard input or file specified by the InFile parameter. This command compares the adjacent rows first, and then drops the second and subsequent copies of the row. Repeated rows must be adjacent. (Use the Sort command to make all duplicate rows contiguous before issuing the Uniq command.) Finally, the Uniq command writes the final separate line to the standard output or to the file specified by the outfile parameter. The InFile and outfile parameters must specify a different file. If the input file is represented by "-", read from standard input, and the input file must be a text file. A text file is a file that contains characters that are organized in one or more lines. The lengths of these lines cannot exceed 2048 bytes (including all newline characters), and they cannot contain null characters. By default, the Uniq command compares all rows. If the-f Fields or-fields flag is specified, the Uniq command ignores the number of fields specified by the Fields variable. field is a string that separates it from other strings with one or more < spaces > characters. If the-s Characters or-characters flag is specified, the Uniq command ignores the number of fields specified by the Characters variable. The value specified for the Fields and Characters variables must be a positive decimal integer. The current locale determines the < blank > character used by the-f flag and how the-s flag interprets bytes as characters. If the execution succeeds, the Uniq command exits and returns a value of 0. Otherwise, the command exit return value is greater than 0. Flag-C before the output line plus the number of times each row appears in the input file. -D displays duplicate rows only. -U displays only rows that are not duplicates. -F Fields ignores the number of fields specified by the Fields variable. If the value of the Fields variable exceeds the number of fields in the input row, the Uniq command is compared with an empty string. This sign is equivalent to the-FIELDS flag. -S Characters ignores the number of characters specified by the Characters variable. If the value of the Characters variable exceeds the number of characters in the input line, the Uniq is entered with an empty stringRow comparison. If the-f and-s flags are specified, the Uniq command ignores the number of characters specified by the-s Characters flag and begins after the field specified by the-F Fields flag. This sign is equivalent to the +CHARACTERS flag. -fields ignores the number of fields specified by the Fields variable. This sign is equivalent to the-f Fields flag. +characters ignores the number of characters specified by the Characters variable. If both the-Fields and +characters flags are specified, the Uniq command ignores the number of characters specified by the +characters flag and starts after the field specified by the-FIELDS flag. This flag is equivalent to the-s Characters flag. -C Displays the output at the beginning of each line plus the number of times the bank appears in the file. It can replace the-U and-D options. -D displays duplicate rows only. -U displays only the rows that are not duplicated in the file. -N the first n fields are ignored together with the blanks before each field. A field is a non-space, tab-delimited string that is separated by tabs and spaces (fields are numbered from 0 onwards). + n the first n characters are ignored, before the characters are skipped (the characters are numbered starting 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. Exit Status This command returns the following exit value: 0 The command ran successfully. >0 an error occurred. When a supplemental file is processed, duplicate rows may appear in its output file. For example, if you use the Cat command to merge two files and then sort by using the sort command, duplicate rows may occur. You can then use the Uniq command to remove these duplicate rows from the output file, leaving only the unique sample of each record
Example to delete a duplicate row in a file named fruit and save it to a file named Newfruit, enter: Uniq fruit newfruit If the fruit file contains the following lines: Apples apples peaches Pears As cherries cherries The Newfruit file will contain the following lines after you run the uniq command: Apples peaches pears Bananas cherries file/usr/bin/uniq contains uniq commands.
# uniq-cThe use of, for example: Harley casely weedly Harley Linda #cut-C 1-8 | Sort | Uniq-c > Result.txt 1 casely 2 Harley 1 Linda 1 Weekly
1. Displays the rows that are not duplicated in the file example. uniq-u Example 2. Displays the rows that are not duplicated in the file example, starting with the 2nd character in the 2nd field. Uniq-u-1 +1 Example
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.