Gentoo Archives: gentoo-user

From: Christer Ekholm <che@××××××.se>
To: gentoo-user@l.g.o
Cc: Teresa and Dale <teendale@×××××××××××××.com>
Subject: [gentoo-user] Re: [OT] Question about duplicate lines in file
Date: Mon, 12 Jun 2006 18:11:51
Message-Id: 86y7w2qmwh.fsf@poke.chrekh.se
In Reply to: Re: [gentoo-user] [OT] Question about duplicate lines in file by Teresa and Dale
1 Teresa and Dale <teendale@×××××××××××××.com> writes:
2
3 >
4 >
5 > Thanks, read the man page, it was short so it didn't take long. I tried
6 > this:
7 >
8 > uniq -u /home/dale/Desktop/hosts /home/dale/Desktop/hostsort
9 >
10 > It doesn't look like it did anything but copy the same thing over.
11 > There are only 2 lines missing. Does spaces count? Some put in a lot
12 > of spaces between the localhost and the web address. Maybe that has a
13 > affect??
14
15 The problem with uniq is that it (according to the manpage),
16
17 "Discard all but one of successive identical lines"
18
19 You need to have a sorted file for uniq to do what you want, or sort
20 it with the -u option
21
22 sort -u hosts > hostsort
23
24 If you don't want to ruin your original order you have to do something
25 else. This is one way of doing it with perl.
26
27 perl -ne 'print unless exists $h{$_}; $h{$_} = 1' hosts > hostsort
28
29 --
30 Christer
31
32 --
33 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Re: [OT] Question about duplicate lines in file Alan McKinnon <alan@××××××××××××××××.za>