Re: uniq without sort <-------------- GURU NEEDED

gnuist006 [at] gmail.com wrote:
<snip>
> I want uniq without sorting the initial order.

My AWK is rusty, but this should work:

awk '!seen[$0] { seen[$0] = $0; print $0 }'

Not sure how empty lines would work out.
William Ahern [ Fr, 25 Januar 2008 15:14 ] [ ID #1915913 ]

Re: uniq without sort <-------------- GURU NEEDED

On Fri, 25 Jan 2008 06:14:03 -0800, William Ahern wrote:
> gnuist006 [at] gmail.com wrote:
> <snip>
>> I want uniq without sorting the initial order.
>
> My AWK is rusty, but this should work:
>
> awk '!seen[$0] { seen[$0] = $0; print $0 }'
>
> Not sure how empty lines would work out.

Empty lines or lines containing "0" or "00"... would be printed
every time.

awk '!($0 in seen) {seen[$0] = ""; print}'

Ed also gave a condensed version.

--
Stephane
Stephane CHAZELAS [ Fr, 25 Januar 2008 15:24 ] [ ID #1915914 ]
Linux » comp.unix.shell » Re: uniq without sort <-------------- GURU NEEDED

Vorheriges Thema: Re: uniq without sort <-------------- GURU NEEDED
Nächstes Thema: Re: uniq without sort <-------------- GURU NEEDED