Help with a regular expression???

Ray Parrish crp at
Wed Jan 27 16:39:10 UTC 2010

Amedee Van Gasse (ub) wrote:
> On Wed, January 27, 2010 15:06, Kevin O'Gorman wrote:
>> However that may be, I would suggest a perl filter, which is a one-liner
>> suitable for a pipeline.
>>    perl -p -e 's/    ([^ ])/_ \1/g;'
>> translation:
>>    -p: copy everything in a loop
>>    -e: statement for the loop follows
>>    s/   /   /g:   do a substitution on everything (g=multiple times on a
>> line)
>>    (  ): remember this
>>    [^ ]: a character class consisting of any one non-space character.
>> Probably does not match newlines either.
>>    \1  : the first remembered thing
>> Hope this helps.
> The same regex syntax can be used with the bash command sed:
> sed 's/    ([^ ])/_ \1/g'
> This *may* be a bit faster than using heavyweight perl. OTOH perl can do a
> lot more than sed, so it depends on what you want to do.
Thanks for the quick answer, and forgive me for being ignorant, but how 
would I call that sed command to get it to work on a variable, and 
return it's value into that variable?

Suppose the variable name is DescriptionSection, how do I pipe the sed 
command to it?

Thanks again, Ray Parrish

Linux dpkg Software Report script set..
Ray's Links, a variety of links to usefull things, and articles by Ray.
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.

More information about the ubuntu-users mailing list