[pmwiki-users] FW: cookbook "ShellTools" (was: Include specific lines of text on a page)

Dominique Faure dominique.faure at gmail.com
Mon Jan 21 08:01:32 CST 2008

On Jan 21, 2008 12:39 PM, Hans <design5 at softflow.co.uk> wrote:
> Sunday, January 20, 2008, 10:21:57 PM, Peter & Melodye Bowers wrote:
> > How would you differentiate between these 2 calls which do very different
> > things:
> > Tail -n 20 file1 file2 | grep 'mytext'
> > Grep 'mytext' file1 file2 | tail -n 5
> I am aware of the difference, and can see the power in combining
> various markup expression, nesting them etc.
> But I am not at all clear how this can be done efficiently when
> processing multiple pages.
> Therefor my first reaction was to create just one tool, and factor
> into it some options which may ideally be better as separate markup
> expressions.
> I need to sit down and think on it.
> > Another option would be to implement something like this:
> > {(shell tail -n 20 file1 file2 | grep "mytext")}
> > {(shell grep "mytext" file1 file2 | tail -n 5)}
> This looks daunting, and I confess I do not like the nomenclature.
> Even "Shell Tools" seems to be wrong in PmWiki context. We do not have a
> shell. And there are probably many users not familiar with unix/linux
> terminology.
> I don't quite see the point of trying to translate Linux shell tools
> with their unchanged syntax. I think it is better to use syntax
> which is commonly in use in PmWiki, and use descriptive naming if
> possible.
> > Anyway, obviously (tail...) is the simplest possible tool to implement
> > (except head) but it does show the nesting and stuff...
> Why create separate 'head' and 'tail' markup expressions? Why not just
> one, if one is needed at all?
> >> Looking again at the (:include ..:) options I realise that in the
> >> grep.php script I lost the ability to source text not just from whole
> >> pages, but from specified sections. I think it would be useful to gain
> >> that too.
> > This would be a very powerful feature - I have no idea how it's implemented,
> > but I've been reading enough of your stuff in the forum to know that you are
> > very experienced in that field.  And this may be one of the places where it
> > makes a lot of sense to deviate from simple text-file-processing and do
> > something wiki-specific.
> This could be part of the 'head and tail' tool or function.
> > If I wanted to find the first n lines or the last n lines there could be an
> > insertion of a (head...) or (tail...) at any level outside the (grep...).  I
> > don't know if I'm adequately showing how powerful these simple tools can be
> > when given the flexibility to order them and combine them in a freeform
> > way...
> yes you do. I just don't know an efficient way for multiple page
> processing having separate markup expressions.
> ~Hans

Well, I don't wnat to sell my soup here, but here's my $0.02 on the topic:

I've already provided a working implementation ablr to handle
expression nesting in
With this recipe, the expressions may become something like:

{(grep 'mytext' (tail n=20 page1 page2))}


{(tail n=5 (grep 'mytext' page1 page2))}

Then, the real difficult thing is to provide a way to propagate the
real data from one command to another.

One solution might be to "cache" the command output stream into an
internal php variable and offer a kind of handle onto it:

Each command should be able to fetch it's data input stream both from
an "external" source (page1, page2) or a previously filled "internal"
stream result.

Another 'cat' elementary command would be required to output
"internal" streams into page content. the previousl command may be

{(cat (grep 'mytext' (tail n=20 page1 page2)))}


{(cat (tail n=5 (grep 'mytext' page1 page2)))}


More information about the pmwiki-users mailing list