Help with a regular expression???

Ray Parrish crp at cmc.net
Wed Jan 27 17:04:12 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.
>   
Ok, here is what I just tried -

DescriptionSection="  - Multidimensional Array Objects
* Efficient arrays of homogeneous machine types (floats, longs,
_ complex doubles)
* Arbitrary number of dimensions
* Sophisticated structural operations
  - Universal Function Objects
* Support mathematical functions on all Python objects
* Very efficient for array objects"
DescriptionSection=`echo | sed 's/    ([^ ])/_ \1/g'`
echo "$DescriptionSection"

And I get the following cryptic error, which tells me nothing. Can you help?

sed: -e expression #1, char 19: invalid reference \1 on `s' command's RHS

Thanks, Ray Parrish


-- 
Linux dpkg Software Report script set..
http://www.rayslinks.com/LinuxdpkgSoftwareReport.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com






More information about the ubuntu-users mailing list