Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I remove duplicates from a list

0 views
Skip to first unread message

#! /shell/nerd

unread,
Nov 22, 2009, 2:46:28 AM11/22/09
to
My list is

B
A
C
E
D
A
E

If I fire sort -u on it it's yield -

A
B
C
D
E

But what I want is -

B
A
C
E
D

Janis Papanagnou

unread,
Nov 22, 2009, 2:59:45 AM11/22/09
to

Subject: How can I remove duplicates from a list

awk '!a[$0]++' yourfile


Janis

Chris F.A. Johnson

unread,
Nov 22, 2009, 3:00:10 AM11/22/09
to

awk '!x[$0]++' FILE

--
Chris F.A. Johnson, author <http://shell.cfajohnson,com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====

0 new messages