fixed-length-record

How do I read fixed-length records in Perl?

What's the best way to read a fixed length record in Perl. I know to read a file like: ABCDE 302 DEFGC 876 I can do while (<FILE>) { $key = substr($_, 0, 5); $value = substr($_, 7, 3); } but isn't there a way to do this with read/unpack? ...

Best practices for fixed-width processing in .NET

I'm working a .NET web service that will be processing a text file with a relatively long, multilevel record format. Each record in the file represents a different entity; the record contains multiple sub-types. (The same record format is currently being processed by a COBOL job, if that gives you a better picture of what we're looking a...

What is the most simple/elegant way to calculate the length of a number written as text ?

Given the maximum possible value, how to simply express the space needed to write such number in decimal form as text ? The real task: logging process ids (pid_t) with fixed length, using gcc on Linux. It'd be good to have a compile time expression to be used in the std::setw() iomanipulator. I have found that linux/threads.h header co...

Regex for fixed width field

I need to match a fixed width field on a file layout with a regular expression. The field is numeric/integer, always have four characters and is included in the range of 0..1331. When the number is smaller than 1000, the string is filled with left zeros. So all these examples are valid: 0000 0001 0010 1000 1331 But the following must...

.NET Library For Fixed Length Text Files

I'm looking for a .NET (much preferably open source in C#) library for dealing with fixed length field text files. It wouldn't be too much to write one, but existing, tested work is always nicer, to start with. I will be extracting data in fixed length fields from files produced by a PBX. Each PBX has its own file format, as well a se...

How to export data into a prn file (fixed width with space fill) in Rails

I did not see this kind of task done anywhere and was wondering how I could export data in a .prn file format in RoR. The idea would be to have: field 1 -> length: 6 chars -> content: "blah" field 2 -> length: 8 chars -> content: "foo" field 3 -> length: 4 chars -> content: "bar" and convert it to a line which would be like: "blah...

MySQL insert multiple fixed length values manually

Hi there, I want to insert multiple values in a table where the value in one of the column increments sequentially. However, the sequence is a bit complex because of business requirements. The single insert would go something like this: INSERT INTO blah (col1, col2) VALUES ('SU0001', 'myemail'); Now, col1 is the value that needs to ...

Iterate through files and read records

What is the fastest way to the following in C# 3.5 : Iterate through files in a directory Read the file's records (fixed length of 247 characters) Convert the fixed length string of each record to a Struct or Class. Thanks ...

C# - Can FileHelper FieldConverter routines refer to other fields in the record?

I am using the excellent FileHelpers library to process a fixed-length airline schedule file. I have a date field, then a few fields later on in the record, a time field. I want to combine both of these in the FileHelpers record class, and know there is a custom FieldConverter attribute. With this attribute, you provide a custom functi...

Is there a public / private key encryption scheme that will not change a message's length?

Is there a public / private key encryption scheme that will not change a message's length? I would like to encrypt a message one packet at a time, but if the packet grows, it would no longer just be one packet long. ...

Creating a fixed length output string with sprintf containing floats

Hi, I'm trying to create a file which has the following structure: - Each line has 32 bytes - Each line looks like this format string: "%10i %3.7f %3.7f\n" My Problem is the following: When i have a negative floating point numbers the line gets longer by one or even two characters because the - sign does not count to the "%3.7f". Is...

Reading a text file with fixed length fields and records in Delphi

I need to read data from a text file where the field lengths and record lengths are fixed. Fields are either zero padded or space padded, always appear in the same order and each record is terminated by a CRLF. The file can have one of three possible record types determined by the first character in the record. So far I've create a base...

What programs or techniques do you use for reading/manipulating files with fixed length records?

When mocking up test data for our product, or debugging customer data, it would be nice to have an app that is able to highlight columns or groups of columns as fields, or even to have the editor be aware of which columns are grouped together into fields. Currently using Vim, which is the best I've come across so far for this task. I'm...