Results 1 to 4 of 4

Thread: Uniq to remove echoed lines

  1. #1
    Join Date
    Nov 2010
    Beans
    69

    Uniq to remove echoed lines

    I have noticed that even when using the correct synatx, uniq does not remove the lines I have echoed into a file.

    say, I echo in the following:
    Code:
    echo "Line1" >> file
          echo "Line2" >> file
          echo "Line1" >> file
    so the file contains those lines.

    Then, I run it through uniq:
    Code:
    cat file | uniq >> file_no_duplicates
    but the contents of file_no_duplicates is still the same. I have tried it multiple different ways, but can't figure it out. Any ideas why?

    Thanks!
    You people are helpful! Thanks!

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Uniq to remove echoed lines

    uniq only works with sorted files.
    Filter adjacent matching lines from INPUT
    so do:
    Code:
    sort file| uniq
    or shorter for simple cases:
    Code:
    sort -u file
    Last edited by MadCow108; July 30th, 2011 at 11:40 PM.

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Uniq to remove echoed lines

    http://pubs.opengroup.org/onlinepubs...ties/uniq.html

    The uniq utility shall read an input file comparing adjacent lines, and write one copy of each input line on the output.
    http://ifaq.wap.org/computers/abcsofunix.html

    U is for uniq, which is used after sort, and
    V is for vi, which is hard to abort.
    「明後日の夕方には帰ってるからね。」


  4. #4
    Join Date
    Nov 2010
    Beans
    69

    Re: Uniq to remove echoed lines

    Ohhhhhh..... that would be why. Thank you!
    You people are helpful! Thanks!

Bookmarks

Posting Permissions

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