In the Linux system operation, the content of the text will inevitably appear duplicate lines. If you delete it manually, it will be more troublesome when you have more quantity. So, is there any way to quickly delete duplicate lines? The following small series will introduce you to how to use the uniq command to delete duplicate lines in Linux.
a, uniq used to do
repeated lines of text, basically not what we want, so we should get rid of. There are other commands under Linux that can remove duplicate lines, but I think uniq is still a convenient one. When using uniq, pay attention to the following two points
1. When working with text, it is generally used in combination with the sort command, because uniq does not check duplicate lines unless they are adjacent lines. If you want to sort the input first, use sort -u.
2, when the text operation, if the field is a first null character (usually including spaces and tabs), then non-null characters, the null characters before the characters in the field will be skipped
Second, uniq parameter description
The code is as follows:
[zhangy@BlackGhost ~]$ uniq --help
Usage: uniq [options]. . . [File]
Filter adjacent matching lines from input files or standard input and write to output files or standard output. "/p" "p" does not attach any options when matching lines will be merged at the first occurrence. "/p" The parameters that must be used for the "p" long option are also required for short options.
-c, --count //prefix each line with a prefix number indicating the number of occurrences of the corresponding line
-d, --repeated //output only duplicate lines
-D, --all-repeated //Export only duplicate lines, but there are a few lines that output a few lines
-f, --skip-fields=N //-f Number of segments ignored , -f 1 ignore the first paragraph
-i, --ignore-case //not case
-s, --skip-chars=N //root-f a bit Like, but -s is ignored, how many characters in the back - s 5 ignore the last 5 characters
-u, --unique //remove the duplicate, all displayed, root mysql's distinct function It's a bit like
-z, --zero-terminated end lines with 0 byte, not newline
-w, --check-chars=N //after the Nth character of each line The content is not checked
--help //Show this help and exit
--version //Show the version information and exit
where -z doesn't know what With
three, test the text file uniqtest
code as follows:
This is a test
this is a test
this is a test
i am tank
i love tank
i love Tank
this is a test
whom have a try
WhoM have a try
you have a try
i want to Abure
those are good men
we are good men
IV, example explanation
The code is as follows:
[zhangy@BlackGhost Mytest]$ uniq -c uniqtest
3 this is a test
1 i am tank
2 i love tank
1 this is a test //and the first line is repeated
1 whom have a try
1 WhoM have a try
1 you have a try
1 i want To abroad
1 we are good men
1 we are good men
From the above example we can see that a feature of uniq, when checking for duplicate lines, Only adjacent rows are checked. Repeat the data, there must be a lot of them that are not adjacent.
The code is as follows:
[zhangy@BlackGhost mytest]$ sort uniqtest
Debian system, some packages can not be deleted for some reason, very troublesome when cleaning up t
What is the /etc/group file, and what does the /etc/group file do? In fact, the /etc/group file in t
The find command is mainly used for file search. It has been described in detail in the previous art
For Wndows users, the Minimize/Maximize/Close button is placed in the upper right c
Teach you how to add a personalized display in the Linux login interface
Detailed method of configuring CentOS devices using Quagga software
CentOS 5.5 prohibits single-user mode approach
Linux viewing system installed kernel operation method
Ubuntu shutdown can not shut down how to solve?
CentOS system implements SSH passwordless login method
How to achieve synchronization between different terminals in Linux system
Linux system safely delete files skills
What should I do if Linux cannot be full screen under VMWare VM?
Tips for learning Linux system commands
Ubuntu Unity online search only shows the skills of the terminal application
Win2K "secret weapon" file comparison tool (1)
What should I do if the win7 computer sound suddenly becomes smaller?
Win7 system can not format SD card how to do
System Daquan teaches you to solve various overheating methods of CPU overheating
Win8 Standard Edition, Win8 Enterprise Edition, Win8 Professional Edition Features
Win8.1 blue screen prompt error 0x00000139 how is it going? Solution tutorial
Win10 computer boot blue screen prompt error code 0x00000050 how to do?
How to restore the IE icon to the desktop after the Win8/8.1 system is installed?