Converting one record to many
Moderator: DosItHelp
Re: Converting one record to many
Thanks abc0502 for your help, it work's!
Re: Converting one record to many
This is a different (clearer, I think) method:
Previous Batch file assume that:
- There is not empty lines in the input file
- Each R-type record is correctly formatted, with no spaces
Maximum input line length for SET /P command is 1024 characters; this means that the maximum number of movements in R-type records is 67 (this can not be fixed).
Code: Select all
@echo off
setlocal EnableDelayedExpansion
call :ProcessFile < input.txt > output.txt
goto :EOF
:ProcessFile
set line=EOF
set /P line=
if %line:~0,3% equ EOF exit /B
if %line:~0,1% neq R (
echo %line%
) else (
set R-record=%line:~0,15%
set moves=!R-record:~-2!
if "!moves:~0,1!" equ "0" set moves=!moves:~1!
rem Store each movement in an array
set type=%line:~15%
for /L %%i in (1,1,!moves!) do (
set movement[%%i]=!type:~0,15!
set type=!type:~15!
)
rem Output each movement
for /L %%i in (1,1,!moves!) do (
echo !R-record!!movement[%%i]!!type!
)
)
:endif
goto ProcessFile
Previous Batch file assume that:
- There is not empty lines in the input file
- Each R-type record is correctly formatted, with no spaces
Maximum input line length for SET /P command is 1024 characters; this means that the maximum number of movements in R-type records is 67 (this can not be fixed).
input.txt wrote:H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTBETA135798642CTZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
output.txt wrote:H201209110000011022E
C10001 000R000000000040000000006
X0003012100000000000102200000784L
R20120911110101ALFA123456789CTX
X0003012100000110222010209000784L
R20120911110403ALFA123456789CTY
R20120911110403BETA135798642CTY
R20120911110403ZETA246897531CTY
T2012091111080000DFRFGT07609530000002030
Re: Converting one record to many
That is neat,
But I don't understand this:
But I don't understand this:
Code: Select all
set line=EOF
set /P line=
if %line:~0,3% equ EOF exit /B
if %line:~0,1% neq R (
Re: Converting one record to many
When SET /P command read an empty line (or reach the End Of File), it does NOT modify the previous value of the variable, so the way to detect these situations is by previously load a value that can not exist in the file (I used "EOF" string in this solution).
This is the reason because the file can not contain empty lines (although this limitation may be fixed).
Antonio
This is the reason because the file can not contain empty lines (although this limitation may be fixed).
Antonio
Re: Converting one record to many
When SET /P command read an empty line (or reach the End Of File), it does NOT modify the previous value of the variable
@Aacini, thanks for the clarification, that is a new info to me
Re: Converting one record to many
I am using a batch to convert a record in several records. The logic will always be to find a certain type of record ("TXAR") create several records, as many as the number of blocks of 99 existing carcateres the register.
Since the final output for each record must contain the first 13 characters of the records and then the bloc of 99 carcateres.
example
input:
<Header 12 characters> <Block 1 - with 99 characters> <Block 2 - with 99 characters> <Block 3 - with 99 characters>
output:
<Header 12 characters> <Block 1 - with 99 characters>
<Header 12 characters> <Block 2 - with 99 characters>
<Header 12 characters> <Block 3 - with 99 characters>
however for records with more than 1000 characters is not working properly, it didn't convert the record with more than 999 characters
any idea what could be the problem?
An example of the source file
The source code that in using int he batch file
Since the final output for each record must contain the first 13 characters of the records and then the bloc of 99 carcateres.
example
input:
<Header 12 characters> <Block 1 - with 99 characters> <Block 2 - with 99 characters> <Block 3 - with 99 characters>
output:
<Header 12 characters> <Block 1 - with 99 characters>
<Header 12 characters> <Block 2 - with 99 characters>
<Header 12 characters> <Block 3 - with 99 characters>
however for records with more than 1000 characters is not working properly, it didn't convert the record with more than 999 characters
any idea what could be the problem?
An example of the source file
Code: Select all
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000256LT 00000001000EUR0000000000400000000029023000CT0000025600000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT0000025100000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000716LT 00000001000EUR0000000000400000000029023000CT0000071600000000000000000002050000000000100600000566LT 00000001001EUR0000000000400000000023023000CT0000056600000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
The source code that in using int he batch file
Code: Select all
set input=C:\tmp\09_24_32_003_IN_RMS.txt
set output=C:\tmp\09_24_32_003_Output.dat
del "%output%"
touch "%output%"
Setlocal EnableDelayedExpansion
For /F "tokens=* delims=" %%A in ('Type "%input%"') Do (
set "line=%%A"
IF "!line:~0,4!" NEQ "TXAR" ( Echo !line!>>"%output%"
) Else (
IF "!line:~0,4!" EQU "TXAR" (
Call :strLen "!line!" "len_line"
IF "!len_line!" GTR "112" (
set /a end = len_line - 99
for /l %%b in (13,99,!end!) Do Echo !line:~0,13!!line:~%%b,98!!line:~-1!>>"%output%"
) Else ( Echo !line!>>"%output%" )
)
)
)
Exit /B
:strLen string len --
:$created 20140302 :$changed 20140312 :$categories StringOperation
(
SETLOCAL ENABLEDELAYEDEXPANSION
set "str=A%~1"
set "len=0"
for /L %%A in (13,-1,0) do (
set /a "len|=1<<%%A"
for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"
)
)
(
ENDLOCAL
IF "%~2" NEQ "" SET /a %~2=%len%
)
EXIT /b
Re: Converting one record to many
RMSoares wrote:however for records with more than 1000 characters is not working properly, it didn't convert the record with more than 999 characters
any idea what could be the problem?
How many times in this thread were you told that BATCH files do have line length limitations!
Re: Converting one record to many
There is any why to resolved this limitation of 1024 characters ?
Re: Converting one record to many
Do you have an authentic file to test with (say on dropbox) and information about how it is to be processed?
Re: Converting one record to many
Hi,
the example taht i had inclued in my post is an export from the input file of the process
or you can get it in https://dl.dropboxusercontent.com/u/20579791/09_24_32_003_IN_RMS.txt
thanks in advance four your help
regards
the example taht i had inclued in my post is an export from the input file of the process
Code: Select all
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000256LT 00000001000EUR0000000000400000000029023000CT0000025600000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT0000025100000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000716LT 00000001000EUR0000000000400000000029023000CT0000071600000000000000000002050000000000100600000566LT 00000001001EUR0000000000400000000023023000CT0000056600000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
or you can get it in https://dl.dropboxusercontent.com/u/20579791/09_24_32_003_IN_RMS.txt
thanks in advance four your help
regards
Re: Converting one record to many
RMSoares wrote:Hi,
the example taht i had inclued in my post is an export from the input file of the process
You said this was the format
example
input:
<Header 12 characters> <Block 1 - with 99 characters> <Block 2 - with 99 characters> <Block 3 - with 99 characters>
but what you are showing us has 100 characters on line 1 and fewer on the next lines.
How do you explain that?
Re: Converting one record to many
Hi,
there is only two records, the first with 806 charcaters and the second record with 1004 characters
there is only two records, the first with 806 charcaters and the second record with 1004 characters
Code: Select all
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000256LT 00000001000EUR0000000000400000000029023000CT0000025600000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT0000025100000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000716LT 00000001000EUR0000000000400000000029023000CT0000071600000000000000000002050000000000100600000566LT 00000001001EUR0000000000400000000023023000CT0000056600000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
Re: Converting one record to many
Foxidrive, the forum is wrapping the lines. Download the text file. But you are still correct. The original explanation of the data format is different then the latest data format example.
Re: Converting one record to many
RMSoares wrote:Hi,
there is only two records, the first with 806 charcaters and the second record with 1004 characters
ok, and thanks Squashman.
RMSoares please show us the output file that you need, from the input file you have shown.
Re: Converting one record to many
Good Morning,
the formatting of the file has been changed, is currently fomatting is that indicated
It is not possible to indicate the number of blocks that each record will contain or indicate what the maximum number of blocks per file.
Based on the format indicated, the format of the output will be as follows.
Based on the example, two records from the input file process
is expected the following output
with the current process already can correctly process correctly the 1º records,
but in the case of the 2nd records is not processed correctly. It pass the full record, with any transformation to the output
Any idea how I can process the records with higher dimension?
Thank you for your help
the formatting of the file has been changed, is currently fomatting is that indicated
Code: Select all
<Header 12 characters> <Block 1 - with 99 characters> <Block 2 - with 99 characters> <Block 3 - 99 characters with> ... <Block n - with 99 characters>
It is not possible to indicate the number of blocks that each record will contain or indicate what the maximum number of blocks per file.
Based on the format indicated, the format of the output will be as follows.
Code: Select all
<Header 12 characters> <Block 1 - with 99 characters>
<Header 12 characters> <Block 2 - with 99 characters>
<Header 12 characters> <Block 3 - with 99 characters>
...
<Header 12 characters> <Block n - with 99 characters>
Based on the example, two records from the input file process
Code: Select all
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000001200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT0000420900000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000256LT 00000001000EUR0000000000400000000029023000CT0000025600000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT0000025100000000000000000001200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000001200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT0000143500000000000000000002100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT0000096400000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000716LT 00000001000EUR0000000000400000000029023000CT0000071600000000000000000002050000000000100600000566LT 00000001001EUR0000000000400000000023023000CT0000056600000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT0000071700000000000000000001200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
is expected the following output
Code: Select all
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT000042090000000000000000000
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT000042090000000000000000000
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT000042090000000000000000000
TXAR0023012251200000000000101800004209LT 00000002000EUR0000000000400000000021023000CT000042090000000000000000000
TXAR0023012252100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT000009640000000000000000000
TXAR0023012251200000000000101800000256LT 00000001000EUR0000000000400000000029023000CT000002560000000000000000000
TXAR0023012251200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023012251200000000000101800000251LT 00000001000EUR0000000000400000000029023000CT000002510000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT000014350000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT000014350000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT000014350000000000000000000
TXAR0023072111200000000000101800001435LT 00000002000EUR0000000000400000000057023000CT000014350000000000000000000
TXAR0023072112100000000000102000000964LT 00000001561EUR0000000000400000000039023000CT000009640000000000000000000
TXAR0023072111200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
TXAR0023072111200000000000101800000716LT 00000001000EUR0000000000400000000029023000CT000007160000000000000000000
TXAR0023072112050000000000100600000566LT 00000001001EUR0000000000400000000023023000CT000005660000000000000000000
TXAR0023072111200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
TXAR0023072111200000000000101800000717LT 00000001000EUR0000000000400000000029023000CT000007170000000000000000000
with the current process already can correctly process correctly the 1º records,
Code: Select all
set input=C:\tmp\09_24_32_003_IN_RMS.txt
set output=C:\tmp\09_24_32_003_Output.dat
del "%output%"
touch "%output%"
Setlocal EnableDelayedExpansion
For /F "tokens=* delims=" %%A in ('Type "%input%"') Do (
set "line=%%A"
IF "!line:~0,4!" NEQ "TXAR" ( Echo !line!>>"%output%"
) Else (
IF "!line:~0,4!" EQU "TXAR" (
Call :strLen "!line!" "len_line"
IF "!len_line!" GTR "112" (
set /a end = len_line - 99
for /l %%b in (13,99,!end!) Do Echo !line:~0,13!!line:~%%b,98!!line:~-1!>>"%output%"
) Else ( Echo !line!>>"%output%" )
)
)
)
Exit /B
:strLen string len --
:$created 20140302 :$changed 20140312 :$categories StringOperation
(
SETLOCAL ENABLEDELAYEDEXPANSION
set "str=A%~1"
set "len=0"
for /L %%A in (13,-1,0) do (
set /a "len|=1<<%%A"
for %%B in (!len!) do if "!str:~%%B,1!"=="" set /a "len&=~1<<%%A"
)
)
(
ENDLOCAL
IF "%~2" NEQ "" SET /a %~2=%len%
)
EXIT /b
but in the case of the 2nd records is not processed correctly. It pass the full record, with any transformation to the output
Any idea how I can process the records with higher dimension?
Thank you for your help