# Automated Text File Manipulation in DOS or Windows



## Joe4 (Sep 16, 2004)

Let me preface this by saying that we need the following to be done is something that will run on DOS/Windows (and not Unix) and will not require the purchase of any new software.  I imagine it can probably done with some sort of Scripting language.

We have a fixed width, space delimited text file.  Each line is 803 spaces long.  Space 803 is an indicator that indicates whether the record is a Participant Record (value = 1), or a Detail Record (value = 2).  Each and every Participant Record is immediately followed by some number of Detail Records (at least 1 for each Participant).  

On the Detail Records (2), there is important identifying information in spaces 794-802.  Unfortunately, this data also needs to be placed the Participant Records (1) for index purposes, but does not exist there.

So there are two things we would like to do.  The first is essential, but the second is less important and we can work around it other ways.

1.  We need to add the index from the Detail Records (2) found in spaces  794-802 to the Participant Record (1) in spaces 1-9.  I envision that whis is how it would work logically:  Loop through all the records, when you come to a record with the value of 1 in space 803, copy the value found in spaces 794-802 of the NEXT record, and paste it in spaces 1-9.

2.  After we are finished with Step 1, split the text files into two text files, one that contains all the Participant Records (1), and one that contains all the Detail Records (2).

The goal, after we finish writing script to do this is to program it with a batch file to do this automatically.

Any advice is appreciated.


----------

