Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Location
    Vancouver Canada
    Posts
    2

    Question Unanswered: 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.

  2. #2
    Join Date
    Aug 2003
    Location
    Argentina
    Posts
    780

    Re: deleting repetitions in a file using sed/awk?

    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.

  3. #3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •