[plug] Help..how do I match /usr/local but not ./usr/local ?

James Devenish devenish at guild.uwa.edu.au
Fri Feb 27 11:21:25 WST 2004


Hi,

In message <403EB616.9090106 at iinet.net.au>
on Fri, Feb 27, 2004 at 11:14:30AM +0800, Lawrie Abbott wrote:
> sed -i -e 's|/usr/local|/usr|g' filename
> 
> but there are instances in one of the files that  contains instances of 
> "./usr/local" that I want left untouched.

There are two common ways, depending on the "semantics" that you desire.
If it weren't for the 'g' at the end of your expression, I might imagine
that you wanted to match against the 'start of the line' only. That can
be done by adding a ^ symbol, like this:

    s|^/usr/local|/usr|g

However, to match /usr/local anywhere within the string without
accepting ./usr/local, you need to do something like:

    s|(^|[^.])/usr/local|/usr|g

(The above means that /usr/local may be matched at the start of a line
OR anywhere else where it is preceded by something other than a full
stop.)

If /usr/local will never appear at the start of the line, you can
simplify the expression down to:

    s|[^.]/usr/local|/usr|g





More information about the plug mailing list