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 Duplicate lines from File Nysif Steve UNIX for Dummies Questions & Answers 18 09-09-2007 05:57 AM
How to redirect duplicate lines from a file???? zing_foru UNIX for Dummies Questions & Answers 3 04-25-2007 04:03 AM
Duplicate lines in the file guptan UNIX for Advanced & Expert Users 3 05-18-2006 02:28 AM
Remove Duplicate Lines in File Teh Tiack Ein Shell Programming and Scripting 5 01-12-2006 04:30 AM
Removing duplicate lines ignore case hellsd UNIX for Dummies Questions & Answers 17 12-02-2004 06:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-25-2007
Registered User
 

Join Date: Sep 2006
Posts: 25
removing duplicate lines from a file

Hi,

I am trying to remove duplicate lines from a file. For example the contents of example.txt is:

this is a test
2342
this is a test
34343
this is a test
43434

and i want to remove the "this is a test" lines only and end up with the numbers in the file, that is, end up with:

2342
34343
43434

thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-25-2007
Registered User
 

Join Date: Dec 2006
Location: CA,United States
Posts: 174
grep -v "^t" <filename>
Reply With Quote
  #3 (permalink)  
Old 01-25-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by ocelot
Hi,

I am trying to remove duplicate lines from a file. For example the contents of example.txt is:

this is a test
2342
this is a test
34343
this is a test
43434

and i want to remove the "this is a test" lines only and end up with the numbers in the file, that is, end up with:

2342
34343
43434

thanks
Code:
grep -v "[[:alpha:]]" file
Reply With Quote
  #4 (permalink)  
Old 01-25-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,865
Code:
# this prints only one line for each distinct record in oldfile
awk '!x[$0]++' oldfile > newfile

# this completely removes all occurrances of all duplicated lines
awk 'x[$0]++ == 2' oldfile > t.sed
grep -v -f t.sed  oldfile > newfile
The other given solutions are data dependent, ie., using the special characteristics of duplicated data in your example to filter.
Reply With Quote
  #5 (permalink)  
Old 01-25-2007
Registered User
 

Join Date: Sep 2006
Posts: 25
thanks guys that worked a treat!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0