Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-14-2010, 03:13 PM
|
#1
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Rep:
|
Delete Duplicate Lines in a file, leaving only the unique lines left
Hello. i've seen several simple commands used to delete duplicate lines from a file, but I've yet to see a command that can leave a file with only the unique lines.
So, for example, here is the file:
1
2
3
1
2
3
4
5
6
I want to have it so that after the command is run on the file, it looks like this:
4
5
6
Any ideas?
-Thanks for the help.
|
|
|
01-14-2010, 03:16 PM
|
#2
|
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
try the `uniq` command
Sasha
|
|
|
01-14-2010, 03:22 PM
|
#3
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Original Poster
Rep:
|
how does that delete the lines that are 1 2 or 3? I think using unique i can get a file that reads:
1
2
3
4
5
6
but not one that reads only
4
5
6
Am i wrong?
--Thanks
|
|
|
01-14-2010, 03:25 PM
|
#4
|
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594
|
Check the man page; observe the -u option, to print only unique lines.
Sasha
|
|
|
01-14-2010, 03:28 PM
|
#5
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Original Poster
Rep:
|
Perfect.
Here is the command i use: cat filename | sort | uniq -u
The issue i had is that uniq can do it, but only if the file is first sorted.
-Thanks for the quick help.
|
|
|
01-14-2010, 05:59 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,441
|
UUOC (useless use of cat), use
sort file|uniq -u
|
|
|
01-14-2010, 06:18 PM
|
#7
|
Member
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554
Original Poster
Rep:
|
Even Better. Thanks.
|
|
|
All times are GMT -5. The time now is 03:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|