The-u parameter of the sort command for basic text processing-uniq command is only valid for key-value segments. sort will discard records with the same key-value segments even if the other parts are different. To put it simple, Linuxshell uses the existing tools and commands in Linux in a certain way (process control and entry... the-u parameter of the sort command for basic text processing-uniq command is only valid for key-value segments. sort will discard records with the same key-value segments even if the other parts are different. Linux shell is simply a method of reorganizing existing Linux tools and commands in a certain way (process control and condition judgment, the use of text tools and commands occupies most of the content in the Shell learning process. as long as you have mastered the use of these tools, it is just a few days to learn the Shell. This document describes how to use the uniq command to display or delete duplicate lines in text. Www.2cto.com uniq command format: uniq [-c |-d |-u] [-f Fields] [-s Characters] [-Fields] [+ Characters] [InFile [OutFile] Usage instructions: if the uniq command is successfully executed, the uniq command exits and the return value is 0. Otherwise, the return value of the exit command is greater than 0. The uniq command deletes duplicate lines in the file. The uniq command reads standard input or files specified by the InFile parameter. This command first compares adjacent lines, and then removes the subsequent copies of the second line and the row. Duplicate rows must be adjacent. this is required. if you do not believe in adjacent rows, uniq cannot be merged, that is, the same rows in the distance cannot be unique. remember. (Before sending the uniq command, use the sort command to adjacent all repeated rows .) Finally, the uniq command writes the final individual line to the standard output or the file specified by the OutFile parameter. The InFile and OutFile parameters must specify different files. In www.2cto.com, the InFile input file must be a text file. This text file contains characters in one or more lines. The length of these rows cannot exceed 2048 bytes (including all line breaks) and cannot contain null characters. By default, the uniq command compares all lines in the LAMP basic centos tutorial. 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, with one or more <空格> It is separated from other strings. 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 Fields and Characters variables must be a positive decimal integer. The current local language environment determines the-f flag used <空白> Characters and how the-s flag interprets bytes as characters. Parameter description:-c deletes duplicate rows and then outputs the text content, and adds the number of times each row appears in the input file before the output row. -D: only duplicate rows are displayed. -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 line, the uniq command uses an empty string for comparison. This flag is equivalent to the-Fields flag. -U only displays non-duplicate rows. -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, uniq compares it with a null string. If both the-f and-s flag are specified, the uniq command ignores the number of Characters specified by the-s Characters flag, starting from the field specified by the-f Fields flag. This flag is equivalent to the + Characters flag. -Fields ignores the number of Fields specified by the Fields variable. This flag is equivalent to the-f Fields flag. + Characters ignores the number of Characters specified by the Characters variable. If both the-Fields and + Characters 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. Uniqe-c-d-u # cat fruits.txt appleapplebanana % region # uniq fruits.txt applebanana % region # uniq-c fruits.txt 2 apple 1 banana 1% % banana 1 orange 1 ORANGE 1 Persimmon if in ascending order of the number of occurrences, I wrote it myself, hee hee # uniq-c fruits.txt | sort-t ''-nk1 1 banana 1% % banana 1 orange 1 ORANGE 1 Persimmon 2 apple # uniq-c-d fruits.txt 2 apple # uniq-c -u fruits.txt 1 banana 1% % banana 1 orange 1 ORANGE 1 Persimmon
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:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.