[PLUG] SED Help Needed -- UPDATE
Fred James
fredjame at fredjame.cnc.net
Tue Feb 22 15:21:35 UTC 2011
Galen Seitz wrote:
> Rich Shepard wrote:
>
>> Yes. Somewhat. And why not totally I don't -- yet -- understand. It does
>> make sense that if characters are going to be grouped in the pattern part of
>> the expression, then all characters need to be grouped. Including the single
>> comma. Per John's suggestion I dropped the '.*' (intending multiple digits
>> preceding the comma), yet not all instances of the pattern are substituted.
>> The first lines of the input and output files show this.
>>
>> Input:
>>
>> 73261,25||0||7/1/1947|D|N|N||H|C|32031|087|N19|19N|E20|20E|04||||MD|39.54,119.74|NV003|M|SPARKS
>> AIR PARK|||||||2/2/1946|D|||125|||125,8.00,0,2,31,1,2.00||||||G|G|||3|MEL MEYER|RT 1 BOX 10 RENO
>> NV||3|NV003|CLIDDELL|7/11/2003|HWOOD|7/21/2003|F|1/28/1946|||264442.24,4380360.93
>>
>> Output:
>>
>> 73261|25||0||7/1/1947|D|N|N||H|C|32031|087|N19|19N|E20|20E|04||||MD|39.54|119.74|NV003|M|SPARKS
>> AIR PARK|||||||2/2/1946|D|||125|||125|8.00|0,2|31|1,2.00||||||G|G|||3|MEL MEYER|RT 1 BOX 10 RENO
>> NV||3|NV003|CLIDDELL|7/11/2003|HWOOD|7/21/2003|F|1/28/1946|||264442.24|4380360.93
>>
>> The first five instances of the pattern have the pipe substituted for the
>> comma. Yet, in the middle of the second line (0,2 and 1,2.00) are not changed.
>> In both cases the preceeding pattern is a single digit rather than 2 or more
>> digits.
>>
>
> That's because the leading 0 in 0,2 and the leading 1 in 1,2 were part
> of the previous match. Sorry, I'm not sure what the correct solution
> is in this case.
>
Running the command twice against the input, cleared up the stragglers.
The SED file would look like this ...
{
s/\([0-9]\)\(,\)\([0-9]\)/\1|\3/g
s/\([0-9]\)\(,\)\([0-9]\)/\1|\3/g
}
Hope that helps
Regards
Fred James
More information about the PLUG
mailing list