Code Comments
Programming Forum and web based access to our favorite programming groups.I have an app that is reading through a file and reformatting it. Currently, it expects there to be 12 or more fields, and each one gets formatted specially. However, just recently, it was discovered that occasionally some of the input fields can be so large that they crash into the previous field. As an example, what normally would : Jan 12.34 56.0 789.0 ... shows up as Jan 12.34 56.0-100.0 ... Does anyone have a technique by which I could 'loop through' all the fields, looking for this case (Each time, the field would match [0-9]+-[0-9] + ), and a) split the two fields, and b) reset the record so that , for example in the second example above, I could 'correct' the data so that it became Jan 12.34 56.0 -100.0 ... before the remainder of the processing takes place. Or am I forced to do that before awk starts reading the data? -- <URL: http://wiki.tcl.tk/ > In God we trust. Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. <URL: mailto:lvirden@yahoo.com > <URL: http://www.purl.org/NET/lvirden/ >
Post Follow-up to this messageIn article <c2q4jd$3t0$4@srv38.cas.org>, <lvirden@yahoo.com> wrote: > > >I have an app that is reading through a file and reformatting it. >Currently, it expects there to be 12 or more fields, and each one gets >formatted specially. > >However, just recently, it was discovered that occasionally some of the >input fields can be so large that they crash into the previous field. > >As an example, what normally would : >Jan 12.34 56.0 789.0 ... > >shows up as >Jan 12.34 56.0-100.0 ... > >Does anyone have a technique by which I could 'loop through' all the fields , >looking for this case (Each time, the field would match [0-9]+-[0-9 ]+ ), >and a) split the two fields, and b) reset the record so that , for example >in the second example above, I could 'correct' the data so that it >became >Jan 12.34 56.0 -100.0 ... >before the remainder of the processing takes place. In gawk: $0 = gensub(/([0-9.]+)(-[0-9.]+)/,"\\1 \\2","g") John -- John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Post Follow-up to this messageAccording to John DuBois <spcecdt@deeptht.armory.com>: :In gawk: : : $0 = gensub(/([0-9.]+)(-[0-9.]+)/,"\\1 \\2","g") : Awesome - thanks so much! That's really sweet! I hadn't thought to reassign the resulting string back to $0 to cause the fields to be recreated! -- <URL: http://wiki.tcl.tk/ > In God we trust. Even if explicitly stated to the contrary, nothing in this posting should be construed as representing my employer's opinions. <URL: mailto:lvirden@yahoo.com > <URL: http://www.purl.org/NET/lvirden/ >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.