[SLUG] Quick question

Al Girling al at gcguk.demon.co.uk
Mon Jul 14 23:46:23 BST 2008


Hi John,

On Mon, Jul 14, 2008 at 08:33:06PM BST, John Allsopp wrote:
> Hope everyone's well.
> 
> Quick question.
> 
> In
> sed -i 's/KoolTrax/KoolTrax™/g' *.php*
> 
> it's ignoring the &
> 
> Presumably it's interpreting it in some way.

I suspect you're seeing KoolTraxKoolTrax#153; instead of the expected
KoolTrax™

> How do I make it treat the & like the other characters?

You need to escape the '&' with a backslash like:

sed -i 's/KoolTrax/KoolTrax\™/g' *.php*

Of course, you could use this to your advantage by writing your regex
as:

sed -i 's/KoolTrax/&\™/g' *.php*

because the Ampersand captures the search expression and reuses it as
part of the replacement.

Something else to note is your search expression isn't restricted to
KoolTrax.  It seems unlikely in this instance, but if your search was
for say, quick.  As the expression is currently, it would match quickly,
quickest etc.  So you would need to use:

sed -i 's/\<KoolTrax\>/&\&#153;/g' *.php*

Toodle pip,

Al

-- 
Al Girling

Linux User: #290080             <http://counter.li.org>
Home-page:                      <http://al.sdf-eu.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.lug.org.uk/pipermail/scarborough/attachments/20080714/1e02298f/attachment.bin


More information about the Scarborough mailing list