Login | Register RSS

Questions

All Questions
Apache [2]
Automotive [1]
Contracting [1]
Electronics [1]
Gardening [1]
Home [3]
Linux [20]
Miscellaneous [2]
MySQL [2]
Perl [1]
Tea [1]
WiFi [1]
Windows [1]

Linux 
Finding Unique Lines In Files
Posted on 09/20/2014

During the course of a workday, I encounter repeating information within data files; which contain usernames, orderIDs, or other single lines of text.
In many of these cases, I need to obtain a list of the unique lines within these files.  Here is how I accomplish it.

From the command line, use sort to reorder the file data & then pass it to uniq to remove similar consecutive lines.

sort FILE | uniq

The above command works fine if you don't mind the order of the lines being changed.


Another option is to use "sort -u" and then redirect the output to lpr or another file.

For example:

sort -u FILE | lpr

or

sort -u FILE >> OTHERFILE

If you like this site or any of its content, please help promote it. Use the social media buttons below to help spread the word. Don't forget to post in the comments section.

  Print   Email
Latest Blog Posts:
Latest Pages:

© 2017 BuildDesignCreate.com • All Rights Reserved
Privacy PolicyAdvertise with UsContact UsSite Map