Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Splitting fields

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/ >

Report this thread to moderator Post Follow-up to this message
Old Post
lvirden@yahoo.com
03-20-04 01:24 AM


Re: Splitting fields
In 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/

Report this thread to moderator Post Follow-up to this message
Old Post
John DuBois
03-20-04 01:24 AM


Re: Splitting fields
According 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/ >

Report this thread to moderator Post Follow-up to this message
Old Post
lvirden@yahoo.com
03-20-04 01:24 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:00 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.