Pull random line from a file

Rob Park rbpark at ualberta.ca
Fri Sep 6 14:00:20 PDT 2002


Alas! Archaic spake thus:
> On Thu, Sep 05, 2002 at 10:31:17PM -0500, Kevan Shea wrote:
> > On Thu, 5 Sep 2002 20:57:58 -0600, Rob Park <rbpark at ualberta.ca> wrote:
> > > 
> > > This ought to do it:
> > > 
> > > rand($.) < 1 && ($line = $_) while <>;
> > > 
> > > ... OH, you wanted BASH? heh, oops ;)
> > > 
> > 
> > Thanks Larry ;)
> 
> HAHAHAHA. That's funny! :D

Ok, here's the bash:

perl -e 'rand($.) < 1 && ($line = $_) while <>' filename

Happy now? ;)

-- 
Rob 'Feztaa' Park
http://members.shaw.ca/feztaa/
--
For an idea to be fashionable is ominous, since it must afterwards be
always old-fashioned.
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-chat' in the subject header of the message



More information about the lfs-chat mailing list