zsh-users
 help / color / mirror / code / Atom feed
* Having random output from a file
@ 2012-04-02 17:19 Mark van Dijk
  2012-04-02 17:25 ` Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mark van Dijk @ 2012-04-02 17:19 UTC (permalink / raw)
  To: zsh-users

Hello,

I have a file that contains quotes that are separated by a blank line. Can zsh
help me to randomly output a quote from that file or should I use awk, or grep
or so? Should the first quote be prefaced by a blank line?

Thanks for helping me,
-Mark.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Having random output from a file
  2012-04-02 17:19 Having random output from a file Mark van Dijk
@ 2012-04-02 17:25 ` Mikael Magnusson
  2012-04-02 20:10   ` Mark van Dijk
  2012-04-03 10:23 ` Eike von Seggern
       [not found] ` <20120403102304.GA12996__48421.5200799101$1333452094$gmane$org@matzbach>
  2 siblings, 1 reply; 5+ messages in thread
From: Mikael Magnusson @ 2012-04-02 17:25 UTC (permalink / raw)
  To: Mark van Dijk; +Cc: zsh-users

On 2 April 2012 19:19, Mark van Dijk <lists+zsh@internecto.net> wrote:
> Hello,
>
> I have a file that contains quotes that are separated by a blank line. Can zsh
> help me to randomly output a quote from that file or should I use awk, or grep
> or so? Should the first quote be prefaced by a blank line?
>
> Thanks for helping me,
> -Mark.

Are you trying to reinvent fortunes? Just separate the quotes by a
line that has a % on it and you can use fortunes directly. :)

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Having random output from a file
  2012-04-02 17:25 ` Mikael Magnusson
@ 2012-04-02 20:10   ` Mark van Dijk
  0 siblings, 0 replies; 5+ messages in thread
From: Mark van Dijk @ 2012-04-02 20:10 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

On Mon, 2 Apr 2012 19:25:32 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:

> On 2 April 2012 19:19, Mark van Dijk <lists+zsh@internecto.net> wrote:
> > Hello,
> >
> > I have a file that contains quotes that are separated by a blank
> > line. Can zsh help me to randomly output a quote from that file or
> > should I use awk, or grep or so? Should the first quote be prefaced
> > by a blank line?
> >
> > Thanks for helping me,
> > -Mark.
> 
> Are you trying to reinvent fortunes? Just separate the quotes by a
> line that has a % on it and you can use fortunes directly. :)
> 

Oh yes, good plan indeed. When I was reading Voltaire on wikiquotes I
couldn't resist sharing his wisdom. In (t)his regard it is remarkable
both how little has changed through the years and how ironic each quote
appears to be under this email. :-)

-- 
It is difficult to free fools from the chains they revere.
  -- Voltaire, 'Le dîner du comte de Boulainvilliers' (1767)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Having random output from a file
  2012-04-02 17:19 Having random output from a file Mark van Dijk
  2012-04-02 17:25 ` Mikael Magnusson
@ 2012-04-03 10:23 ` Eike von Seggern
       [not found] ` <20120403102304.GA12996__48421.5200799101$1333452094$gmane$org@matzbach>
  2 siblings, 0 replies; 5+ messages in thread
From: Eike von Seggern @ 2012-04-03 10:23 UTC (permalink / raw)
  To: zsh-users

On Mon, Apr 02, 2012 at 19:19 +0200, Mark van Dijk wrote:
> Hello,
> 
> I have a file that contains quotes that are separated by a blank line. Can zsh
> help me to randomly output a quote from that file or should I use awk, or grep
> or so? Should the first quote be prefaced by a blank line?
> 
> Thanks for helping me,
> -Mark.

I use this alias to get a random line from a file (so it would only work
in your case if each quote is on a single line)

alias rndline='sort -R | head -1'

But it's not using any zsh magic.

Best
    eike


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Having random output from a file
       [not found] ` <20120403102304.GA12996__48421.5200799101$1333452094$gmane$org@matzbach>
@ 2012-04-03 18:08   ` Christian Neukirchen
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Neukirchen @ 2012-04-03 18:08 UTC (permalink / raw)
  To: zsh-users

Eike von Seggern <eikevons@yahoo.de> writes:

> I use this alias to get a random line from a file (so it would only work
> in your case if each quote is on a single line)
>
> alias rndline='sort -R | head -1'
>
> But it's not using any zsh magic.

If you depend on GNU coreutils anyway, you can just do "shuf -n1".

-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-03 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-02 17:19 Having random output from a file Mark van Dijk
2012-04-02 17:25 ` Mikael Magnusson
2012-04-02 20:10   ` Mark van Dijk
2012-04-03 10:23 ` Eike von Seggern
     [not found] ` <20120403102304.GA12996__48421.5200799101$1333452094$gmane$org@matzbach>
2012-04-03 18:08   ` Christian Neukirchen

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).