From: Stefan Lang Date: 2005-10-06T05:39:39+09:00 Subject: Re: One-liner removing duplicate lines On Wednesday 05 October 2005 22:34, Ryan Leavengood wrote: > On 10/5/05, Ryan Leavengood wrote: > > I tried creating a version that mimics the Perl one (because Ruby > > also has the -n option), but in the end this seemed easier (and > > much more readable): > > > > ruby -e "puts IO.readlines(ARGV[0]).uniq" infile > outfile > > > > So you are right about using uniq. > > Just for sake of comparison, here is the more "Perl-like" version: > > ruby -ne "s||={};s[$_]||print;s[$_]=1" infile > outfile > > Maybe some Ruby golfers can shorten it some more, but since Ruby > lacks some of the more terse (and obfuscating) features of Perl, it > may not be possible. ruby -ne 'a||={};a[$_]||=(print;1)' infile > outfile -- Stefan