The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

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

Join Date: Sep 2006
Posts: 31
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
  #2 (permalink)  
Old 01-25-2007
Krrishv Krrishv is offline
Registered User
  
 

Join Date: Dec 2006
Location: CA,United States
Posts: 186
grep -v "^t" <filename>
  #3 (permalink)  
Old 01-25-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
  #4 (permalink)  
Old 01-25-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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.
  #5 (permalink)  
Old 01-25-2007
ocelot ocelot is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
thanks guys that worked a treat!
Sponsored Links
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 10:58 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