473,699 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I convert a Text file with variable length records to fixed length records?

21 New Member
Hi,
I am looking for an example to convert a flat text file with variable length records to a flat file with fixed length records. Does anyone have an example?
Dec 27 '06 #1
11 9990
willakawill
1,646 Top Contributor
Hi,
I am looking for an example to convert a flat text file with variable length records to a flat file with fixed length records. Does anyone have an example?
Hi Jim, you will need to know the maximum field length for any strings in the text file
Dec 27 '06 #2
JimN1
21 New Member
Hi Jim, you will need to know the maximum field length for any strings in the text file
I know the size of each field. The beginning portion of the records is fixed ( the first 100 or so bytes). The rest varies according to the record type (ex: 05, 06,10, 30, 50, etc). I need all the records to be fixed (336 length) with a Ctrl/Lf at the end of each record.
An example of the records is:
20817 C A00059530 376480850 PP001755719 056920 CARMICHAEL AVE BETHESDA, MD 20817
20817 C A00059530 376480850 PP001755719 06MARK F THIMMIG
20817 C A00059530 376480850 PP001755719THIM MIG JORDAN C A0005953002 061030B00786 10 000016
20817 C A00059530 376480850 PP001755719THIM MIG JORDAN C A0005953002 061030B00786010 0 003001001020067 061 99203 +000001 +000008000+0000 08000PAPBFA +000000000+0000 02400+000000000 +000000000+0000 00000+000005600 0000{ +000000000+0000 00000+000000000 +000000000+0000 00000 1020060001
Dec 27 '06 #3
willakawill
1,646 Top Contributor
I know the size of each field. The beginning portion of the records is fixed ( the first 100 or so bytes). The rest varies according to the record type (ex: 05, 06,10, 30, 50, etc). I need all the records to be fixed (336 length) with a Ctrl/Lf at the end of each record.
An example of the records is:
20817 C A00059530 376480850 PP001755719 056920 CARMICHAEL AVE BETHESDA, MD 20817
20817 C A00059530 376480850 PP001755719 06MARK F THIMMIG
20817 C A00059530 376480850 PP001755719THIM MIG JORDAN C A0005953002 061030B00786 10 000016
20817 C A00059530 376480850 PP001755719THIM MIG JORDAN C A0005953002 061030B00786010 0 003001001020067 061 99203 +000001 +000008000+0000 08000PAPBFA +000000000+0000 02400+000000000 +000000000+0000 00000+000005600 0000{ +000000000+0000 00000+000000000 +000000000+0000 00000 1020060001
Does the number of fields change from record to record?
Dec 27 '06 #4
JimN1
21 New Member
Does the number of fields change from record to record?
Yes, starting in position 112 (counting from 1) the records have different fields and field sizes. The record types are determined by the record type located in position 110 for a length of 2 characters. Record types are 05, 06, 10, 30, 50, 87, 88.
Dec 27 '06 #5
willakawill
1,646 Top Contributor
Yes, starting in position 112 (counting from 1) the records have different fields and field sizes. The record types are determined by the record type located in position 110 for a length of 2 characters. Record types are 05, 06, 10, 30, 50, 87, 88.
If the data after 112 is significant the you will need to create records that are all as long as the longest one leaving null values in the unused fields of the shorter records
Dec 27 '06 #6
Killer42
8,435 Recognized Expert Expert
If the data after 112 is significant the you will need to create records that are all as long as the longest one leaving null values in the unused fields of the shorter records
I think that is what he actually asked for. :)

Try this quick sample...
Expand|Select|Wrap|Line Numbers
  1. Dim TheRecord As String
  2. Dim L As Long
  3. Const MaxLength As Long = 336
  4. Open "OldFile.Txt" For Input Access Read Shared As #1
  5. Open "NewFile.Txt" For Output Access Write Lock Write As #2
  6. Do Until Eof(1)
  7.   Line Input #1, TheRecord
  8.   L = Len(TheRecord)
  9.   If L < MaxLength Then
  10.    TheRecord = TheRecord & Space$(MaxLength - L)
  11.   End If
  12.   Print #2, TheRecord
  13. Loop
  14. Close
  15.  
Dec 28 '06 #7
willakawill
1,646 Top Contributor
I think that is what he actually asked for. :)

Try this quick sample...
Expand|Select|Wrap|Line Numbers
  1. Dim TheRecord As String
  2. Dim L As Long
  3. Const MaxLength As Long = 336
  4. Open "OldFile.Txt" For Input Access Read Shared As #1
  5. Open "NewFile.Txt" For Output Access Write Lock Write As #2
  6. Do Until Eof(1)
  7.   Line Input #1, TheRecord
  8.   L = Len(TheRecord)
  9.   If L < MaxLength Then
  10.    TheRecord = TheRecord & Space$(MaxLength - L)
  11.   End If
  12.   Print #2, TheRecord
  13. Loop
  14. Close
  15.  
And where are the NULL values in the blank fields?
You are just making the last field very long here.
I have never worked on a project where this would be useful, but I could be wrong.
Dec 28 '06 #8
Killer42
8,435 Recognized Expert Expert
And where are the NULL values in the blank fields?
You are just making the last field very long here.
I have never worked on a project where this would be useful, but I could be wrong.
Granted, there may well be more required, but the original request was just to convert to fixed-length records. I would assume this is only one step in the conversion process.

Oh, and as for "that's what he asked for" I need to read more carefully, huh. :(
Dec 28 '06 #9
JimN1
21 New Member
I think that is what he actually asked for. :)

Try this quick sample...
Expand|Select|Wrap|Line Numbers
  1. Dim TheRecord As String
  2. Dim L As Long
  3. Const MaxLength As Long = 336
  4. Open "OldFile.Txt" For Input Access Read Shared As #1
  5. Open "NewFile.Txt" For Output Access Write Lock Write As #2
  6. Do Until Eof(1)
  7.   Line Input #1, TheRecord
  8.   L = Len(TheRecord)
  9.   If L < MaxLength Then
  10.    TheRecord = TheRecord & Space$(MaxLength - L)
  11.   End If
  12.   Print #2, TheRecord
  13. Loop
  14. Close
  15.  
Yes, this is what I was talking about! Depending on the record type the record ends in varioius lengths. I will give this a try and let you know how it works. The ultimate goal is to get an input file that I can create a shcema for and use as input to map to a destination file using Biztalk. I will let you know how it goes. Thanks.
Dec 29 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

21
39410
by: Sami Viitanen | last post by:
Hello, How can I check if a file is binary or text? There was some easy way but I forgot it.. Thanks in adv.
6
2662
by: Jocknerd | last post by:
I'm a Python newbie and I'm having trouble with Regular Expressions when reading in a text file. Here is a sample layout of the input file: 09/04/2004 Virginia 44 Temple 14 09/04/2004 LSU 22 Oregon State 21 09/09/2004 Troy State 24 Missouri 14 As you can see, the text file contains a list of games. Each game has a date, a winning team, the winning...
10
2027
by: Paul Kooistra | last post by:
I need a tool to browse text files with a size of 10-20 Mb. These files have a fixed record length of 800 bytes (CR/LF), and containt records used to create printed pages by an external company. Each line (record) contains an 2-character identifier, like 'A0' or 'C1'. The identifier identifies the record format for the line, thereby allowing different record formats to be used in a textfile. For example: An A0 record may consist of:
6
10097
by: Kifah Abbad | last post by:
hi guys, First thanks for the support in my last question posted here. Now i have been trying today to read about finding a way to solve this (simple?) problem....which is...i have a string lets say "Leila" from user and i want to search a text file with a table of values "name of girl" "hair color", so like this somehow:
6
1859
by: Adrian Lin | last post by:
Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put...
12
2977
by: Brian Henry | last post by:
first question... I have a flat file which unfortinuatly has columns seperated by nulls instead of spaces (a higher up company created it this way for us) is there anyway to do a readline with this and not have it affected by the null? because it is right now causes truncated data at wierd places... but as soon as i manually with a hex editor change char(00) to char(20) in the files it reads prerfectly... which leads me to my 2nd...
7
3126
by: Hallvard B Furuseth | last post by:
I'm trying to clean up a program which does arithmetic on text file positions, and also reads text files in binary mode. I can't easily get rid of it all, so I'm wondering which of the following assumptions are, well, least unportable. In particular, do anyone know if there are real-life systems where the text file assumptions below don't hold? For text mode FILE*s,
13
3277
by: Neil Cerutti | last post by:
Many of the file formats I have to work with are so-called fixed-format records, where every line in the file is a record, and every field in a record takes up a specific amount of space. For example, one of my older Python programs contains the following to create a fixed-format text record for a batch of new students: new = file("new.dat", "w") if not new:
6
4443
by: ssharpjr | last post by:
Hi Guys, I'm new to Python (mostly) and I'm wanting to use it for a new project I'm faced with. I have a machine (PLC) that is dumping its test results into a fixed- length text file. I need to pull this data into a database (MySQL most likely) so that I can access it with Crystal Reports to create daily reports for my engineers.
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9055
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8944
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8899
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3075
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 we have to send another system
2
2364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.