LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 03-25-2008, 10:28 AM   #1
shabev
LQ Newbie
 
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
removing duplicate entries


Hi

Can any one help me for the following query.

I have one file which has the entry like as follows

Mar 24 09 abcd
Mar 24 09 abcd
Mar 24 11 pqrs
Mar 24 13 wxyz
Mar 24 13 wxyz
Mar 24 22 abcd
Mar 25 01 abcd
Mar 25 02 abcd
Mar 25 03 wxyz
Mar 25 06 wxyz
Mar 25 06 wxyz
Mar 25 07 pqrs
Mar 25 07 pqrs
Mar 25 07 pqrs
Mar 25 08 pqrs

My requirement is to find out identical entry and keep only one entry and remove other entries from this file.

for example The below are identical

Mar 24 09 abcd
Mar 24 09 abcd

i want to remove one entry from this and keep one entry

another set

Mar 25 07 pqrs
Mar 25 07 pqrs
Mar 25 07 pqrs

i want to remove two entry from this and keep one entry

So requirement is to remove duplicate entries from the file.
Is there any linux command to achive the same?
 
Old 03-25-2008, 10:34 AM   #2
l4n3
LQ Newbie
 
Registered: Aug 2006
Posts: 12

Rep: Reputation: 0
If the file is called file.txt do:

#> sort file.txt | uniq > file2.txt

file2.txt will only contain single instances of all the entries.

If the file is already sorted, uniq alone will work...

you could also use `sort -u`

`man sort` should help you out.
 
Old 03-25-2008, 10:35 AM   #3
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
try:
sort -u oldfile > newfile
 
Old 03-25-2008, 10:36 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
See
Code:
man uniq
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find duplicate entries in shell jyotijain21 Linux - Newbie 5 06-23-2008 01:17 AM
Duplicate daylight savings time entries ille.pugil42 Linux - Software 2 03-09-2007 01:17 PM
Duplicate entries in fstab jrdioko Linux - Software 3 08-14-2006 01:08 AM
duplicate entries in grub d_GeNeRiT Fedora 5 01-26-2006 07:22 AM
Duplicate Entries OpenSuSE 10.0 TMan459 SUSE / openSUSE 3 10-19-2005 04:43 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 08:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration