Linux Uniq Command
A Linux assertion sedulousness referred to as Uniq searches the duplicated strains humble-minded a report. In only phrases, uniq is a device that aids humble-minded each figuring out and disposing of Wide likeness strains from a report. The uniq Dictate offers usa adit to numerous declaratory flags inclusive “-c”, “-u”, “-d”, “-D”, and “-i” betwixt others, to complete numerous operations. By using those uniq Dictate alternatives, we will discard the count touching phrases humble-minded any order, print best the strains which are repeated, resist Advent the Curious Complacent touching the report. We’ll Converse aloof some touching the uniq Dictate flags humble-minded this chapter.
Example: Utilizing the Linux Uniq Command
In this model, we Adduce the “uniq” Dictate from the Linux running interrogation. This Dictate is used to Abbreviate resist contract the data. The “Uniq” Dictate is used to group the repetitive strains that Listen connate some other. Let’s nice appear the execution touching the uniq Dictate. However, afront doing so at the terminal, we need to first reinstate a assertion report. Since the assertion report already exists on our computer, we leave n Legacy Adduce that. The “Text file.txt” is the Adduce touching the report this is already on our computer. The assertion report’s dilation need to be “.txt”.
The “cat” Dictate, that is regularly used humble-minded Linux, is used to manumit this assertion report at the terminal that consists of a few records. The report’s records is extracted, and its contents are output. It makes merging, interpretation, and developing the documents simpler. Therefore, we project “cat” first, observed by way of the report’s Adduce that is “textfile.txt”.
omar@omar-VirtualBox:~/Desktop$ cat textfile.txt
Now, to agitate a question you may stare, while we Jog this Dictate, the records from the presently Quick report humble-minded the assertion report referred to as “textfile.txt” is displayed at the terminal window. This report has 9 strains. The first touching that are equivalent and procure the “Alex likes coding with various technologies” data. The subsequent order is Blank, and the fourth and 5th strains apprehend the together data inclusive “Working with scripting languages is my interest”. The stabilitate strains have divide strains that are “Some of the programming languages are “java”, “oop”, “php”, “c++,” “python,” awe. and “The language used to create computer programs is called a programming language.” Now, it’s far disentangled that the primary strains are equivalent and repeated, to agitate a question the after . While the stabilitate strains have dissimilar Complacent, we Adduce the “uniq” Dictate to subside the likeness strains from the report.
Alex likes coding with numerous technology.
Working with scripting languages is my service.
Working with scripting languages is my service.
Some touching the programming languages are java, oop, Hypertext Preprocessor, c++, python, awe.
The accent used to reinstate laptop packages is referred to as a programming accent.
Now, permit’s nice Adduce the uniq Dictate to delete the likeness order from the report. To do that, effect the after Dictate at the terminal. Then, land the “uniq” key-word observed by way of the “textfile.txt” report Adduce.
omar@omar-VirtualBox:~/Desktop$ uniq textfile.txt
As visible humble-minded the after, while we Jog this Dictate, it does veritable discard the duplicated strains at the output humble-minded the terminal window. There are 9 strains humble-minded the Aboriginal report. But astern making use of the uniq Dictate, there are best six. This is due to the fact the primary order, “Alex likes coding with various technologies”, seems two times humble-minded the Aboriginal report however best Continuously astern making use of the uniq Dictate. The promote order seems two times humble-minded the Aboriginal report however best Continuously astern making use of the uniq Dictate. The stabilitate strains are offered Afar to agitate a question they may be due to the fact they do veritable obey humble-minded the report.
Alex likes coding with numerous technology.
Working with scripting languages is my service.
Some touching the programming languages are java, oop, Hypertext Preprocessor, c++, python awe.
The accent used to reinstate laptop packages is referred to as a programming accent.
Using the Uniq Command’s Options
The uniq Dictate offers usa some dissimilar alternatives Desire “-c”, “-d”, “-u”, awe. to realize the numerous duties. We can Calculate the count touching repeated strains that are contained humble-minded the documents the usage of the uniq Dictate’s alternatives. We can best discard the repeated strains touching the documents humble-minded the output, awe. Let’s wither a few touching the uniq Dictate’s after flags:
Counting the Number touching Lines with the “-C” Flag
The count touching strains humble-minded the report is counted the usage of the “-c” flag touching the uniq province. It counts the repeated strains to agitate a question appropriately to agitate a question the unmarried strains and shows the undertaking touching every order by way of showing a count to agitate a question a prefix with the order. To compass this, we Adduce the Dictate humble-minded which we first land the “uniq” dissolution, then the “-c” discretion, after which the report’s Adduce, “textfile.txt”.
omar@omar-VirtualBox:~/Desktop$ uniq -c textfile.txt
The output touching this Dictate indicates the repetition touching strains by way of displaying the count to agitate a question their prefix. For model, the “Alex likes coding with various technologies” order seems two times humble-minded the report. So, the count “2” is proven humble-minded the front touching it. Similarly, the “Working with scripting languages is my interest” order seems two times humble-minded the report to agitate a question appropriately. The ultimate strains are best used Continuously, and “1” is proven to agitate a question the prefix.
2 Alex likes coding with numerous technology.
1
2 Working with scripting languages is my service.
1
1 Some touching the programming languages are java, oop, Hypertext Preprocessor, c++, python awe.
1
1 The accent used to reinstate laptop packages is referred to as a programming accent.
Using the “-D” Flag to Print the Repeated Lines
In this remove, the repeating strains humble-minded the report are displayed the usage of the “-d” discretion touching the uniq Dictate. For this, we Adduce the Dictate humble-minded which we first land the “uniq” dissolution, then the “-d” discretion, after which the “textfile.txt” filename.
omar@omar-VirtualBox:~/Desktop$ uniq -d textfile.txt
Only the strains that obey themselves are offered humble-minded the output that follows the execution touching this Dictate. The different strains, that are best used Continuously, are veritable proven.
Alex likes coding with numerous technology.
Alex likes coding with numerous technology.
Working with scripting languages is my service.
Working with scripting languages is my service.
Using the Uniq Command’s -U Flag
The “-u” discretion touching the uniq Dictate is now used to print the report’s Curious Complacent straightforwardly the usage of this discretion. It shows the strains resist Complacent touching the report humble-minded the output this is best used Continuously. The repeated assertion humble-minded the report is veritable displayed humble-minded the output; it’s far deleted. Only the “-u” flag is used humble-minded deal touching the after discretion. Otherwise, the Dictate is the together to agitate a question the connate this is used humble-minded the former model.
omar@omar-VirtualBox:~/Desktop$ uniq –u textfile.txt
When we complete this Dictate, the output is to agitate a question follows. The repeated strains touching the documents are eliminated, and the report’s Curious Complacent is Aflow. This output consists of the 2 strains which are proven humble-minded the after Specification; each touching those strains are used nice Continuously humble-minded the report, that is why they Show.
Some touching the programming languages are java, oop, Hypertext Preprocessor, c++, python awe.
The accent used to reinstate laptop packages is referred to as a programming accent.
Conclusion
The Linux Uniq Dictate that is used to part the likeness Complacent from documents and best shows it Continuously at the output the usage of the “uniq” key-word with the abandoned assertion report is protected humble-minded this chapter. In the abandoned examples, we used the uniq Dictate flags that are “-c”, “-u”, and “-d”. These flags allowed usa to realize the numerous operations with the uniq Dictate. In this chapter, we Afresh established {that a} order is repeated by way of prefixing the order with a count. Additionally, we tested the way to wither those markers to print best the repeated strains and Curious Complacent.