[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding OR editing line only if not present
From: |
Jamie Wilkinson |
Subject: |
Re: Adding OR editing line only if not present |
Date: |
Fri, 7 Feb 2003 09:44:29 +1100 |
User-agent: |
Internet Messaging Program (IMP) 3.1 |
Quoting Florian Thiel <noroute@web.de>:
> What I want to do is the following:
> Append a certain line if it's not already there. If it's there, see if
> it maches a certain regexp. If it doesn't, replace it.
This is the goal of my cf.ssh which I posted yesterday. Your construct is a bit
shorter, as you're using AppendIfNoLineMatching, whereas I use a Begin/EndGroup.
> LocateLineMatching "^allow="
> BeginGroupIfNoMatch "^allow=10\.\$(nr)\.0\.0/255\.255\.0\.0 127\.0\.0\.1"
> ReplaceLineWith "allow=10\.$(nr)\.0\.0/255\.255\.0\.0 127\.0\.0\.1"
> EndGroup
> DefineClasses "restart_webmin"
This is the only way you can do it. But I'd like to point out that the
ReplaceLineWith takes a quoted-string, not a regex, so you don't need to escape
the fullstops. I'd also not bother with the BeginGroupIfNoMatch line.
Jamie