From: Mark Hubbart Date: 2005-10-09T01:49:28+09:00 Subject: Re: One-liner removing duplicate lines On 10/8/05, Mark Hubbart wrote: > On 10/5/05, Ryan Leavengood wrote: > > On 10/5/05, Damien Wyart wrote: > > > Hello, > > > > > > Converting from Perl to Ruby, I am trying to find an equivalent to this > > > Perl one-liner removing duplicate lines in a file (without sorting it at > > > first) : > > > > > > perl -ne'$s{$_}++||print' infile >outfile > > > > > > I guess uniq method could be used, but I can't find how. > > > > 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. > > Here's a derived version (is this really Ruby?): > > ruby -e'$><<[*$<].uniq' infile > outfile As long as we're mostly obfuscated anyway, we might as well make the whole thing punctuation: ruby -e'$><<([*$<]|[])' infile > outfile cheers, Mark ...who got into the golf round a little late