[H-GEN] regular expressions
Byron Ellacott
bje at apnic.net
Fri Aug 18 00:28:23 EDT 2000
[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics. Please observe the list's charter. ]
On Fri, 18 Aug 2000, Tom Atkinson wrote:
> The following sed script will replace multiple instances of white space
> with one 'a', for example:
> sed 's/ */a/'
There are two problems with this script. The first is that you didn't
include the g flag, so only the first match on each line would be changed:
sed 's/ */a/g'
The second problem is far more severe. ' *' will match 0 or more spaces.
Unfortunately, there happen to be zero spaces between every character, so
passing "hello world" to your script will produce:
ahaealalaoawaoaralada
which is probably not what you had intended.
[Mail saved to folder "incoming-humbug-lists" From Martin Pool respecting Re: []
that's probably Martin saying the same thing as me :)
To fix it, you'd either want to use ' *' or ' +' as your pattern.
--
bje
--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.
More information about the General
mailing list