The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove duplicates from File from specific location gopikgunda Shell Programming and Scripting 1 04-09-2008 03:16 AM
lastlog has duplicates chlawren AIX 1 06-19-2006 05:30 AM
fastest way to remove duplicates. radhika Shell Programming and Scripting 15 11-03-2005 07:27 AM
Removing duplicates giannicello Shell Programming and Scripting 12 09-14-2005 07:12 PM
Sendmail Duplicates OBSESIK UNIX for Dummies Questions & Answers 0 02-28-2005 01:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-16-2008
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
How to remove duplicates without sorting

Hello,


I can remove duplicate entries in a file by:

sort File1 | uniq > File2

but how can I remove duplicates without sorting the file?

I tried cat File1 | uniq > File2 but it doesn't work



thanks
  #2 (permalink)  
Old 01-16-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by orahi001 View Post
Hello,


I can remove duplicate entries in a file by:

sort File1 | uniq > File2

but how can I remove duplicates without sorting the file?

I tried cat File1 | uniq > File2 but it doesn't work



thanks
Many ways using awk or perl. Search this site using the duplicates keyword.
  #3 (permalink)  
Old 01-16-2008
orahi001 orahi001 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 48
Before my post I found on an older post

awk ' !x[$0]++' Infile > outFile


but it was giving syntax errors when exectued.

Then I changed awk to nawk and it worked.



thanks
  #4 (permalink)  
Old 01-17-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
Quote:
sort File1 | uniq > File2
You don't need a sort and uniq for removing duplicates

same can be accomplished by "-u" option

Code:
sort -u filename > new.filename
  #5 (permalink)  
Old 01-17-2008
pp56825 pp56825 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 32
Quote:
Originally Posted by orahi001 View Post
Before my post I found on an older post

awk ' !x[$0]++' Infile > outFile


but it was giving syntax errors when exectued.

Then I changed awk to nawk and it worked.



thanks

try to use nawk or /usr/xpg4/bin/awk
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0