help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about LocateLineMatching


From: Brendan Strejcek
Subject: Re: Question about LocateLineMatching
Date: Wed, 17 Mar 2004 22:19:28 -0600
User-agent: Mutt/1.3.28i

Incidently, does anyone know how I might go about searching in reverse
for a line regex? That is, something like LocateLineMatching, but
backwards?

I have one solution:

    ForEachLineIn "/path/to/file/being/edited"
        BeginGroupIfNoMatch "^target line$"
            IncrementPointer "-1"
        EndGroup
    EndLoop
    # pointer is now at target line, or first line
    # do something to the located line; such as: CommentNLines "1"

This takes advantage of the fact that there can't be more lines in the
file than there are lines in the file. :-)

It works, but the problem is that I want to do this inside another loop,
and nested loops are not allowed.

This was to be used for an edit of lilo.conf which was intended
to ensure that, given some label and some image (for example,
image=/vmlinuz, label=Linux), no other image had the same label.

So the design was, find each section with label=Linux, then search
backwards for the matching image, and if it was incorrect, comment out
that section.

An edit like this is probably too complex to run on production machines,
but I still want to get it to work for fun.

-- Brendan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]