If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > deleting repetitions in a file using sed/awk?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-04, 17:24
nismo nismo is offline
Registered User
 
Join Date: Jan 2004
Location: Vancouver Canada
Posts: 2
Question deleting repetitions in a file using sed/awk?

I have a file say test.txt and it has text entries like
"134
212
278
299
299
300
300
301"

Now I want to delete anything that repeats more than once, hence deleting one entry of 299 and one entry of 300. Since it's dynamic (I wouldn't know what to look for if I were to do a search using regular expression). How can I achieve this using sed or awk?

Thanks for any help you can provide.
Reply With Quote
  #2 (permalink)  
Old 01-09-04, 07:48
gurey gurey is offline
Registered User
 
Join Date: Aug 2003
Location: Argentina
Posts: 780
Re: deleting repetitions in a file using sed/awk?

Quote:
Originally posted by nismo
I have a file say test.txt and it has text entries like
"134
212
278
299
299
300
300
301"

Now I want to delete anything that repeats more than once, hence deleting one entry of 299 and one entry of 300. Since it's dynamic (I wouldn't know what to look for if I were to do a search using regular expression). How can I achieve this using sed or awk?

Thanks for any help you can provide.
Hi,

Please test with cat test.txt|sort -u o cat test.txt|uniq

Gustavo.
Reply With Quote
  #3 (permalink)  
Old 01-09-04, 12:50
nismo nismo is offline
Registered User
 
Join Date: Jan 2004
Location: Vancouver Canada
Posts: 2
cat test.txt|sort -u | cat test.txt|uniq
or simply using the uniq command works.

thanks Gustavo!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On