473,511 Members | 15,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Parse each line by character location

Lie
On Nov 5, 2:29*pm, Dennis Lee Bieber <wlfr...@ix.netcom.comwrote:
[snip]
* * * * So you have a classic (especially for COBOL and older FORTRAN) fixed
field record layout, no?

* * * * I presume the entire file is of a single layout? That would mean
only one splitting format is needed...
[snip]
>
* * * * Note that all fields are still in character format. And has been
noted, I'm sure, if you try to turn the third field into an integer, you
may have problems, depending upon how you do the conversion -- leading 0
implies octal if it were a literal, though it seems int() handles it
correctly (Python 2.5)
from help(int)
| ... If base is zero, the proper base is guessed based on the
| string content. ...

int(x) will always convert x in base 10
int(x, 0) will convert based on literal int notation, i.e. the prefix
'0x' is base 16 (hex), prefix '0' is base 8 (octal), everything else
is base 10.
int(x, n) will convert on base n, where 2 <= n <= 36

if you're still in doubt, just pass the base explicitly to the int:
int(x, 10) (superfluous though)
Nov 5 '08 #1
1 1894
I work with tab-delimited files for a living. Because of the same need
you have, I created a Python script to do this. It has usage
information that is easy to follow (just run it without any
arguments).

I hope someone else finds this useful. I have, and use it every month.
It can be easily modified to create comma-delimited files, but that's
something I never use, so it does tabs.

http://milochik.com/shawn/fwconvert.zip

Usage:
fwconvert -r rulesFile fileName [-t|-f]
or
cat filename | fwconvert -r rulesFile" (-t|-f)

-t (to tab) or -f (to fixed-width) required when piping input to
script. Otherwise, it will be auto-determined.
Rules file format:
fieldStart:fieldLength,fieldStart:fieldLength...
Example:
1:3,4:20,24:5
Nov 5 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2914
by: josh dismukes | last post by:
/// here is the code i'm getting a parse error on the last line of the code which /// is </html> any help will be much appreciated. <?php session_start ();
2
1620
by: Stuart Rogers | last post by:
My hosting service uses PHP 4.3.10 and when I run a php script which works perfectly on my local lan linux server on my hosting service I get this error:- Parse error: parse error, unexpected...
4
1771
by: rolf | last post by:
Hmm, I seem to be missing something basic with regards to SAXParsers. I'm parsing some XML using Java 1.4.2 and SAX, so I extend DefaultHandler and in my startElement() method I detect some kind...
22
5117
by: nick | last post by:
#include <stdio.h> #define BALANCE 5000 int main(){ int balance = BALANCE; return 0; } when i compile it, an error occurs,what's happen?
8
5018
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
9
5720
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
29
2871
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
5
64582
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
64004
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
374
by: Tyler | last post by:
        So you have a classic (especially for COBOL and older FORTRAN) fixed Exactly, I believe COBOL. It is a daily reconciliation with an exchange and our system's orders. One of the problems...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.