I have been reviewing posts on the internet. As well as this forum. But I still don't understand how to create a batch command file that will:
1. Read a Flat-File created by a main-frame system. Approx rec-size is 275 bytes in each record.
2. Bypass the first record, because its not needed by the target system. If one can define the 1st 2 positions in the file to be a record code, that can be used to bypass this header.
3. Need to bypass the last record on the file (as it is blank, and not needed).
4. After that, this is basically a file re-write. Keeping the same record length, and EOL char on each record in the output file.
I have looked at examples of the FOR stmt. But this seems to be reading the whole file as one chunk, into the variable. How do I parse the FOR stmt into reading this file on the logical file markers based upon the fixe length of each record?
Appreciative of any help someone can afford an old main-frame programmer..
Larry
Help with Reading A Fixed Length Record Flat File with a Batch Script
Moderator: DosItHelp
Re: Help with Reading A Fixed Length Record Flat File with a Batch Script
Native batch has no capability to read records based solely on length. The only thing batch can do is read one line at a time, where each line must be terminated by a newline (\n), or carriage return/newline (\r\n)
If your records are not terminated by a newline, then you will have to use some other scripting language such as VBScript, JScript, or PowerShell. Or you could possibly use some 3rd party utility within a batch script.
Dave Benham
If your records are not terminated by a newline, then you will have to use some other scripting language such as VBScript, JScript, or PowerShell. Or you could possibly use some 3rd party utility within a batch script.
Dave Benham
Re: Help with Reading A Fixed Length Record Flat File with a Batch Script
This is an example of how to read fixed-length records from a text file:
This general method may be improved in several ways.
input.txt:
output.txt:
Antonio
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set chunkSize=18
set "input="
call :ReadFile < input.txt
goto :EOF
:ReadFile
call :ReadChunk %chunkSize%
if not defined chunk goto :EOF
echo %chunk%
goto ReadFile
:ReadChunk
if not defined input set /P "input="
if not defined input set "chunk=" & exit /B
set /A sizeM1=%1-1
if "!input:~%sizeM1%!" equ "" (
set "buffer="
set /P "buffer="
set "input=!input!!buffer!"
)
set "chunk=!input:~0,%1!"
set "input=!input:~%1!"
exit /B
This general method may be improved in several ways.
input.txt:
Code: Select all
This is line one This is line two This is line threeThis is line four
output.txt:
Code: Select all
This is line one
This is line two
This is line three
This is line four
Antonio
Re: Help with Reading A Fixed Length Record Flat File with a Batch Script
I work on a mainframe every day and I am really not understanding what your file looks like coming from the mainframe. Too me it sounds like you are working with a variable block file.