[PLUG] SED Help Needed -- UPDATE

Rich Shepard rshepard at appl-ecosys.com
Tue Feb 22 14:27:41 UTC 2011


On Mon, 21 Feb 2011, Fred James wrote:

>     s/\([0-9]\)\(,\)\([0-9]\)/\1|\3/g

Fred, John, et al.:

> Does that help?

   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.

   Almost there!

Rich



More information about the PLUG mailing list