Loading ...
Sorry, an error occurred while loading the content.

47395Re: sort & remove duplicate lines?

Expand Messages
  • Will Fiveash
    Feb 2, 2004
    • 0 Attachment
      On Sun, Feb 01, 2004 at 09:13:31PM -0600, Elliott Hoel wrote:
      > On Sun, Feb 01, 2004 at 08:57:47PM -0500, Tim Musson wrote:
      > > I use Vim for everything, but find myself going to TextPad for one
      > > or 2 things. I was wondering if there is a Vim equivalent?
      > >
      > > The first one and the one I need most often is "sort & remove
      > > duplicate lines". I know I can sort easily with ":n,n!sort", but I
      > > don't know how to remove dups. Can anyone point me in the right
      > > direction?
      > In Unix (I don't know about anything else) sort has the option -u. this
      > sorts and removes duplicate lines (man sort): :%!sort -u. Also see the
      > alternative command uniq (man uniq), which doesn't sort but removes
      > adjacent duplicate lines.

      Another option, where nawk is available, is:

      :%!nawk '!seen[$0]++'

      which will remove duplicate lines and doesn't require sorting or

      Will Fiveash
      Sun Microsystems Inc.
      Austin, TX, USA (TZ=CST6CDT)
      GPG PubKey ID:0x7D31DC39, Key server: www.keyserver.net
    • Show all 22 messages in this topic