Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

How to delete lines in a file that have duplicates or derive the lines that aper once

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-17-2009
necroman08 necroman08 is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 27 December 2010, 11:16 AM EST
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
How to delete lines in a file that have duplicates or derive the lines that aper once

Input:

Code:
a
b
b
c
d
d

I need:

Code:
a
c

I know how to get this (the lines that have duplicates) :
b
d

Code:
sort file | uniq -d

But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem.

Last edited by Yogesh Sawant; 07-17-2009 at 06:00 AM.. Reason: adde code tags
Sponsored Links
    #2  
Old Unix and Linux 07-17-2009
lathavim lathavim is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 1 March 2011, 3:21 PM EST
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
 
sort file | uniq -u

Sponsored Links
    #3  
Old Unix and Linux 07-17-2009
rakeshawasthi rakeshawasthi is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 27 May 2014, 10:05 PM EDT
Location: India
Posts: 379
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by necroman08 View Post
Input:
a
b
b
c
d
d

I need:
a
c

I know how to get this (the lines that have duplicates) :
b
d

Code:
sort file | uniq e



But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem.

doesn't work for me.... If you can make it work... using grep the other thing is possible.

---------- Post updated at 02:17 PM ---------- Previous update was at 02:16 PM ----------

Quote:
Originally Posted by lathavim View Post
Code:
 
sort file | uniq -u

This works though
    #4  
Old Unix and Linux 07-17-2009
necroman08 necroman08 is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 27 December 2010, 11:16 AM EST
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by rakeshawasthi View Post
doesn't work for me.... If you can make it work... using grep the other thing is possible.

---------- Post updated at 02:17 PM ---------- Previous update was at 02:16 PM ----------



This works though
Yea sorry. Wrote it wrongly, it should be:
Code:
sort file | unig -d

.
Wrote rubbish first time, that is because stres Linux

---------- Post updated at 04:07 AM ---------- Previous update was at 04:05 AM ----------

Quote:
Originally Posted by lathavim View Post
Code:
 
sort file | uniq -u

Great! Thanks man.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep and delete lines except the lines with strings vj8436 Shell Programming and Scripting 14 04-17-2009 11:25 AM
Shell script to remove duplicates lines in a file RichElks Shell Programming and Scripting 1 02-25-2009 10:05 PM
duplicates lines with one column different dhanamurthy Shell Programming and Scripting 10 05-07-2008 05:38 AM
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 06:58 AM
delete blank lines or lines with spaces only vascobrito UNIX for Dummies Questions & Answers 3 01-13-2004 06:36 AM



All times are GMT -4. The time now is 11:49 PM.