[PLUG] SED Help Needed -- UPDATE

Fred James fredjame at fredjame.cnc.net
Tue Feb 22 00:51:13 UTC 2011


Rich Shepard wrote:
> On Mon, 21 Feb 2011, Rich Shepard wrote:
>
>   
>>   In English, I want to locate one or more digits followed by a comma and
>> one or more digits, then replace only the comma with a pipe.  What I've
>> tried include:
>> 	s/.*[0-9],[[0-9]/\&|/g
>>     
>
>    More searching with Google lead me to this:
>
> "The section explains how to do the apparently complex task of moving text
> around within lines. Consider, for example, the output of ls: say you want
> to automatically strip out only the size column-- sed can do this sort of
> editing if you use the special \( \) notation to group parts of the regular
> expression together. Consider the following example:
>
>
>  	sed -e 's/\(<[^ ]*>\)\([ ]*\)\(<[^ ]*>\)/\3\2\1/g'
>
> "Here sed is searching for the expression \<.*\>[ ]*\<.*\>. From the chapter
> on regular expressions, we can see that it matches a whole word, an
> arbitrary amount of whitespace, and then another whole word. The \( \)
> groups these three so that they can be referred to in <replace-text>. Each
> part of the regular expression inside \( \) is called a subexpression of the
> regular expression. Each subexpression is numbered--namely, \1, \2, etc.
> Hence, \1 in <replace-text> is the first \<[^ ]*\>, \2 is [ ]*, and \3 is
> the second \<[^ ]*\>."
>
>    So, I tried
>
>  	s/\(.*[0-9]\),\([0-9]\)/\1|\2/g
>
> but nothing was changed. Perhaps closer, but still not there.
>
> Rich
>   
Rich Shepard
     s/\([0-9]\)\(,\)\([0-9]\)/\1|\3/g
Does that help?
Regards
Fred James




More information about the PLUG mailing list