How to cut some blocks off the entire file then save into separated file
Moderator: DosItHelp
How to cut some blocks off the entire file then save into separated file
I have a task to cut off some blocks of entire file (Load_all.M83) then save it into a separated file (Load_NAR.M83).
Here is the outline of this entire file structure, it is a catalog file
;---- Groupe signed binaries
-epackage
;---- Component: EasyPath to Cless
;---- Catalog: Entry Point 0200000.Mxx
9992044568020000_APPCLEP.P3A
9992044568020000_APPCLEP.P3P
9992044690020000_LIBCLEPPX.P3L
9992044691020000_LIBCLEPRNGPX.P3L
9992044689000500_LIBEMVRNG.P3L
8445670405_EmvCoChecksum.P3L
;---- Catalog: JCB JSpeedy 0201.MXX
8445600201_JCB.P3A
9992047269020400_libJCB.P3L
........ (here all bunch of files with similar structure as above)
........
........
;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
;---- Groupe data files
-eimport
device.txt
;---- NAR data files
-eimport
;---- Component: File COMM.INI
;---- Catalog: comm_ini.mxx
COMM.INI
Now I would like to cut off the block all the strings before the below line, in other words, save the string starting from the below lines
;---- NAR signed binaries
and also need to exclude these strings, sometimes it can have more lines in this block
;---- Groupe data files
-eimport
device txt
then save to a separate file as Load_NAR.M83
I also attached these two files as samples
Here is the outline of this entire file structure, it is a catalog file
;---- Groupe signed binaries
-epackage
;---- Component: EasyPath to Cless
;---- Catalog: Entry Point 0200000.Mxx
9992044568020000_APPCLEP.P3A
9992044568020000_APPCLEP.P3P
9992044690020000_LIBCLEPPX.P3L
9992044691020000_LIBCLEPRNGPX.P3L
9992044689000500_LIBEMVRNG.P3L
8445670405_EmvCoChecksum.P3L
;---- Catalog: JCB JSpeedy 0201.MXX
8445600201_JCB.P3A
9992047269020400_libJCB.P3L
........ (here all bunch of files with similar structure as above)
........
........
;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
;---- Groupe data files
-eimport
device.txt
;---- NAR data files
-eimport
;---- Component: File COMM.INI
;---- Catalog: comm_ini.mxx
COMM.INI
Now I would like to cut off the block all the strings before the below line, in other words, save the string starting from the below lines
;---- NAR signed binaries
and also need to exclude these strings, sometimes it can have more lines in this block
;---- Groupe data files
-eimport
device txt
then save to a separate file as Load_NAR.M83
I also attached these two files as samples
- Attachments
-
- sample.7z
- (3.22 KiB) Downloaded 825 times
Last edited by goodywp on 14 Sep 2019 04:57, edited 2 times in total.
Re: How to cut off some blocks off the entire file then save into separated file
cutoff where ? at a specified byte position or based upon the occurrence of a string ?
Re: How to cut off some blocks off the entire file then save into separated file
based upon the occurrence of a string.
cut off all the strings before this line, in other words to save the strings starting from below line
;---- NAR signed binaries
to the end.
but also need to cut off unwanted string (in this block) as
;---- Groupe data files
-eimport
Thanks
Re: How to cut off some blocks off the entire file then save into separated file
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$fileIn=Load_all.M83"
set "$fileOu=Load_NAR.M83"
> "!$fileOu!" type nul
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2>nul' ) do set "$NumberOfLines=%%?"
< "!$fileIn!" (
set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do (
set "$=" &set /P "$="
if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1
if !$at! NEQ 0 (
set /A $filter = 0
if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1
if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!)
)
)
)
Hope there are no exclamation marks and carets in that file because I am not protecting any tokens that are problematic.
Re: How to cut off some blocks off the entire file then save into separated file
Thanks! ED! tried and gotEd Dyreen wrote: ↑22 Nov 2018 16:42Just out of my head, this may work.Code: Select all
@echo off &setlocal enableDelayedExpansion set "$fileIn=Load_all.M83" set "$fileOu=Load_NAR.M83" > "!$fileOu!" type nul for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2>nul' ) do set "$NumberOfLines=%%?" < "!$fileIn!" ( set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do ( set "$=" &set /P "$=" if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1 if !$at! NEQ 0 ( set /A $filter = 0 if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1 if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!) ) ) )
Hope there are no exclamation marks and carets in that file because I am not protecting any tokens that are problematic.
2> was unexpected at this time. It was part of code
Code: Select all
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2>nul' ) do set "$NumberOfLines=%%?"
Code: Select all
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^)' ) do set "$NumberOfLines=%%?"
And there are some cut off towards end, meaning less than expected..
Thanks for the effort!
Re: How to cut off some blocks off the entire file then save into separated file
my mistake, 2>nul should be 2^>nul because it's in a for. You need it because otherwise zero length files will be miscounted as length 1 where it should 0. That is find will echo a message on stream 2 also known as stderr, 2>nul means redirect stream 2 to device nul.goodywp wrote: ↑23 Nov 2018 08:26Thanks! ED! tried and got
2> was unexpected at this time. It was part of codeWhen I took it off, it works but have some extra lines before the StringCode: Select all
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2>nul' ) do set "$NumberOfLines=%%?"
if you can't solve it post an example so we can figure out what you expect and what is happening.
Re: How to cut off some blocks off the entire file then save into separated file
Tried as you suggested and similar to my previous trying.Ed Dyreen wrote: ↑23 Nov 2018 08:39my mistake, 2>nul should be 2^>nul because it's in a for. You need it because otherwise zero length files will be miscounted as length 1 where it should 0. That is find will echo a message on stream 2 also known as stderr, 2>nul means redirect stream 2 to device nul.goodywp wrote: ↑23 Nov 2018 08:26Thanks! ED! tried and got
2> was unexpected at this time. It was part of codeWhen I took it off, it works but have some extra lines before the StringCode: Select all
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2>nul' ) do set "$NumberOfLines=%%?"
if you can't solve it post an example so we can figure out what you expect and what is happening.
Got some extra line before the start string and end up earlier, meaning cut off some wanted strings. I attached the results of this try
as below quote
from above these are extraP
;---- Catalog: ALL_TERMINALS_QATCHER.MXX
9991047171035902_KERNEL_MOD_QATCHER.P3S
9992048009160530_OPT_QATCH.P3P
;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
;---- Component: Tetra Admin Skins 0001
;---- Catalog: TA_skins.mxx
8520830001_SKIN_SK480_320.P3P
;---- Component: NAR Apps Signed Resources
;---- Catalog: NarAppsSignedResources.mxx
8520460101_852046.P3P
;---- Catalog: NarAppsSignedResources.mxx
8295490203_829549.P3P
8296250000_829625.P3P
844
.
.
.
.
and these are missing from 844 and afterwardsP
;---- Catalog: ALL_TERMINALS_QATCHER.MXX
9991047171035902_KERNEL_MOD_QATCHER.P3S
9992048009160530_OPT_QATCH.P3P
;---- Catalog: NarAppsSignedResources.mxx
8295490203_829549.P3P
8296250000_829625.P3P
844
.
.
.
.
Re: How to cut off some blocks off the entire file then save into separated file
I don't see anything wrong, this is what I get when running your input file from the first post. Starting where you said it should and stripping of the line ';---- Groupe data files'. Or do all consecutive lines after the line ';---- Groupe data files' need to be stripped of also until the next line starting with a ";" ?;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
-eimport
device.txt
;---- NAR data files
-eimport
;---- Component: File COMM.INI
;---- Catalog: comm_ini.mxx
COMM.INI
using the fixed version
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$fileIn=Load_all.M83"
set "$fileOu=Load_NAR.M83"
> "!$fileOu!" type nul
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2^>nul' ) do set "$NumberOfLines=%%?"
< "!$fileIn!" (
set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do (
set "$=" &set /P "$="
if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1
if !$at! NEQ 0 (
set /A $filter = 0
if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1
if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!)
)
)
)
exit /b
Re: How to cut off some blocks off the entire file then save into separated file
Very strange, I tried this original input file again using the latest code of yoursEd Dyreen wrote: ↑23 Nov 2018 11:10I don't see anything wrong, this is what I get when running your input file from the first post. Starting where you said it should and stripping of the line ';---- Groupe data files'. Or do all consecutive lines after the line ';---- Groupe data files' need to be stripped of also until the next line starting with a ";" ?;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
-eimport
device.txt
;---- NAR data files
-eimport
;---- Component: File COMM.INI
;---- Catalog: comm_ini.mxx
COMM.INI
using the fixed versionCode: Select all
@echo off &setlocal enableDelayedExpansion set "$fileIn=Load_all.M83" set "$fileOu=Load_NAR.M83" > "!$fileOu!" type nul for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2^>nul' ) do set "$NumberOfLines=%%?" < "!$fileIn!" ( set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do ( set "$=" &set /P "$=" if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1 if !$at! NEQ 0 ( set /A $filter = 0 if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1 if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!) ) ) ) exit /b
got results as below:
10900_FOALMONO_TTF_IT.P3P
9990044261010900_FOALMONO_TTF_BO.P3P
9990044260010900_FOALMONO_TTF_NO.P3P
;---- Catalog: ALL_TERMINALS_PCL_SPMCI.MXX
9990044625050500_LIBPCL.P3L
9990044625050500_LIBPCL.P3P
9990044627050500_PCLVIEW.P3L
9990044626050500_LIBSPMCI.P3L
9990044626050500_LIBSPMCI.P3P
0002046010050500_SPMCIWR.P3A
9992048008160530_OPT_PCL.P3P
;---- Catalog: ALL_TERMINALS_QATCHER.MXX
9991047171035902_KERNEL_MOD_QATCHER.P3S
9992048009160530_OPT_QATCH.P3P
;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Cata
oftware.tmscall.PBT
Re: How to cut off some blocks off the entire file then save into separated file
I also used this site library function as below:
I tried the above code to see if I can get anything, but not working, any reason about the set variable for bmk and src ???
Code: Select all
@ECHO OFF
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
echo.Extracting hello world block into "Load_NAR.M83" file
call:extractFromFile ";---- NAR signed binaries" "DEVICE_ID.TXT">"Load_NAR.M83"
::------------------------------------------------------------------
::-- functions start below here
::------------------------------------------------------------------
:extractFromFile - extract lines from a file between begin and end mark
:: - %~1: begin mark, use '...$' mark to allow variable substitution
:: - %~2: optional end mark, default is end of file
:: - %~3: optional source file, default is THIS file
SETLOCAL
set bmk=;---- NAR signed binaries
set emk=DEVICE_ID.TXT
set src=Load_all.M83
set /a b=-1
set /a e=-1
if "%src%"=="" set src=%~f0& ::- if no source file then assume THIS file
for /f "tokens=1,* delims=:" %%a in ('"findstr /n /b /c:"%bmk%" "%~f0""') do (
set b=%%a
set bmk=%%b
)
if /i %b%==-1 echo.ERROR: begin mark '%bmk%' not found in '%src%'&GOTO:EOF
if "%emk%"=="" (set /a e=2000000000) ELSE (
for /f "delims=:" %%a in ('"findstr /n /b /c:"%emk%" "%~f0""') do (
if /i %b% LSS %%a if /i !e!==-1 set e=%%a& rem -- find only the first one after b
)
)
if /i %e%==-1 echo.ERROR: end mark '%emk%' missing in '%src%'&GOTO:EOF
if /i %b% GEQ %e% echo.ERROR: end mark '%emk%' detected before begin mark '%bmk%' in '%src%'&GOTO:EOF
for /f "delims=: tokens=1,*" %%a in ('"findstr /v /n /b /c:"#$*ReturnAll*$#" "%src%""') do (
if /i %b% LSS %%a if /i %%a LSS %e% (
if "%bmk:~-1%"=="$" (
rem --substitution variables within %%b
call echo.%%b
) ELSE (
rem --no variable substitution
echo.%%b
)
)
)
GOTO:EOF
Re: How to cut off some blocks off the entire file then save into separated file
I downloaded your sample, and I notice the file is using LF as line terminator but dos expects CRLF. So the lines are never terminated and cause the variable to overflow as it can only hold 8kb and your input is 12kb which I believe explains the data getting lost. Then this 8kb is treated as a single line because DOS doesn't use LF as terminator.
If I convert the LF terminators to CRLF it seems ok.
I want you to create a file LFtoCRLF.CMD. In there put thisNow backup your original input and drag and drop it onto LFtoCRLF.CMD. Now try this converted file as your input.
If I convert the LF terminators to CRLF it seems ok.
I want you to create a file LFtoCRLF.CMD. In there put this
Code: Select all
@echo off &setlocal disableDelayedExpansion &title %~n0
set "$iFile=%~1"
set "$oFile=%~dp0%~nx1"
echo.¯ '%$iFile%'
type "%$iFile%" &echo.
echo.® '%$iFile%'
more "%$iFile%" > "%$oFile%"
echo.
echo.¯ '%$oFile%'
type "%$oFile%" &echo.
echo.® '%$oFile%'
Re: How to cut off some blocks off the entire file then save into separated file
Thanks so much ED! I would like to know if there is a better way to do the convert. BTW, I was trying to drag and drop and looks like not working, please a little bit detailsEd Dyreen wrote: ↑23 Nov 2018 14:32I downloaded your sample, and I notice the file is using LF as line terminator but dos expects CRLF. So the lines are never terminated and cause the variable to overflow as it can only hold 8kb and your input is 12kb which I believe explains the data getting lost. Then this 8kb is treated as a single line because DOS doesn't use LF as terminator.
If I convert the LF terminators to CRLF it seems ok.
I want you to create a file LFtoCRLF.CMD. In there put thisNow backup your original input and drag and drop it onto LFtoCRLF.CMD. Now try this converted file as your input.Code: Select all
@echo off &setlocal disableDelayedExpansion &title %~n0 set "$iFile=%~1" set "$oFile=%~dp0%~nx1" echo.¯ '%$iFile%' type "%$iFile%" &echo. echo.® '%$iFile%' more "%$iFile%" > "%$oFile%" echo. echo.¯ '%$oFile%' type "%$oFile%" &echo. echo.® '%$oFile%'
Re: How to cut off some blocks off the entire file then save into separated file
I used this piece code to do the convert and works.goodywp wrote: ↑23 Nov 2018 15:57Thanks so much ED! I would like to know if there is a better way to do the convert. BTW, I was trying to drag and drop and looks like not working, please a little bit detailsEd Dyreen wrote: ↑23 Nov 2018 14:32I downloaded your sample, and I notice the file is using LF as line terminator but dos expects CRLF. So the lines are never terminated and cause the variable to overflow as it can only hold 8kb and your input is 12kb which I believe explains the data getting lost. Then this 8kb is treated as a single line because DOS doesn't use LF as terminator.
If I convert the LF terminators to CRLF it seems ok.
I want you to create a file LFtoCRLF.CMD. In there put thisNow backup your original input and drag and drop it onto LFtoCRLF.CMD. Now try this converted file as your input.Code: Select all
@echo off &setlocal disableDelayedExpansion &title %~n0 set "$iFile=%~1" set "$oFile=%~dp0%~nx1" echo.¯ '%$iFile%' type "%$iFile%" &echo. echo.® '%$iFile%' more "%$iFile%" > "%$oFile%" echo. echo.¯ '%$oFile%' type "%$oFile%" &echo. echo.® '%$oFile%'
Code: Select all
@echo off &setlocal disableDelayedExpansion
set "$iFile=Load_old.M72"
set "$oFile=Load_all.M72"
(for /f ^"usebackqeol^=^
delims^=^" %%? in (
"%$iFile%"
) do (echo(%%?)
)> "%$oFile%"
echo.
echo.'%$oFile%'
type "%$oFile%"
pause
exit
Re: How to cut off some blocks off the entire file then save into separated file
Hi ED,Ed Dyreen wrote: ↑23 Nov 2018 11:10I don't see anything wrong, this is what I get when running your input file from the first post. Starting where you said it should and stripping of the line ';---- Groupe data files'. Or do all consecutive lines after the line ';---- Groupe data files' need to be stripped of also until the next line starting with a ";" ?;---- NAR signed binaries
-epackage
;---- Component: Tetra Admin Resources 0001
;---- Catalog: TA_resources.mxx
8520440000_852044.P3P
;---- Component: Tetra Admin Proxy Lib 0001
;---- Catalog: TAProxylib_app.mxx
8400000100000000_libTAProxy.P3L
;---- Component: NAR TSA Tetra 0521
;---- Catalog: 8295010521_TSA.MXX
8295010521_TSA.P3A
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
;---- Component: ORKI App 1.0.0.0020
;---- Catalog: orki_app.mxx
8520010002_852001.P3A
;---- Component: Tetra Admin App 0003
;---- Catalog: TA_app.mxx
8400000100000300_TetraAdmin.P3A
-eimport
device.txt
;---- NAR data files
-eimport
;---- Component: File COMM.INI
;---- Catalog: comm_ini.mxx
COMM.INI
using the fixed versionCode: Select all
@echo off &setlocal enableDelayedExpansion set "$fileIn=Load_all.M83" set "$fileOu=Load_NAR.M83" > "!$fileOu!" type nul for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2^>nul' ) do set "$NumberOfLines=%%?" < "!$fileIn!" ( set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do ( set "$=" &set /P "$=" if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1 if !$at! NEQ 0 ( set /A $filter = 0 if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1 if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!) ) ) ) exit /b
just realized that I also need to cut off these lines
;---- Component: NAR KIA Tetra 0521
;---- Catalog: 8295000521_KIA.MXX
8295000521_KIA.P3A
I tried add these 3 lines in your code and works. Only thing is these files can change in future in terms of version
Code: Select all
@echo off &setlocal enableDelayedExpansion
set "$fileIn=Load_all.M72"
set "$fileOu=Load_NAR.M72"
> "!$fileOu!" type nul
for /F %%? in ( '^( find /V /C"" ^< "!$fileIn!" ^) 2^>nul' ) do set "$NumberOfLines=%%?"
< "!$fileIn!" (
set /A $at = 0 &for /L %%i in ( 1, 1, !$NumberOfLines! ) do (
set "$=" &set /P "$="
if defined $ if "!$:;---- NAR signed binaries=!" NEQ "!$!" set /A $at = 1
if !$at! NEQ 0 (
set /A $filter = 0
if defined $ if "!$:;---- Groupe data files=!" NEQ "!$!" set /A $filter = 1
if defined $ if "!$:;---- Component: NAR KIA Tetra 0521=!" NEQ "!$!" set /A $filter = 1
if defined $ if "!$:;---- Catalog: 8295000521_KIA.MXX=!" NEQ "!$!" set /A $filter = 1
if defined $ if "!$:8295000521_KIA.P3A=!" NEQ "!$!" set /A $filter = 1
if !$filter! EQU 0 >>"!$fileOu!" (echo(!$!)
)
)
)
exit /b
Re: How to cut off some blocks off the entire file then save into separated file
The output file will have the same name as the input file and will be placed in the same directory as LFtoCRLF.CMD the input file should be in a different folder or more will be using the same input as output file which doesn't work. If you want the output filename to be different from the input filename so this doesn't happen you can change set "$oFile=%~dp0%~nx1" to set "$oFile=%~dp0_%~nx1" for example.goodywp wrote: ↑23 Nov 2018 15:57Thanks so much ED! I would like to know if there is a better way to do the convert. BTW, I was trying to drag and drop and looks like not working, please a little bit detailsEd Dyreen wrote: ↑23 Nov 2018 14:32I downloaded your sample, and I notice the file is using LF as line terminator but dos expects CRLF. So the lines are never terminated and cause the variable to overflow as it can only hold 8kb and your input is 12kb which I believe explains the data getting lost. Then this 8kb is treated as a single line because DOS doesn't use LF as terminator.
If I convert the LF terminators to CRLF it seems ok.
I want you to create a file LFtoCRLF.CMD. In there put thisNow backup your original input and drag and drop it onto LFtoCRLF.CMD. Now try this converted file as your input.Code: Select all
@echo off &setlocal disableDelayedExpansion &title %~n0 set "$iFile=%~1" set "$oFile=%~dp0%~nx1" echo.¯ '%$iFile%' type "%$iFile%" &echo. echo.® '%$iFile%' more "%$iFile%" > "%$oFile%" echo. echo.¯ '%$oFile%' type "%$oFile%" &echo. echo.® '%$oFile%'
The conversion is done by this single line more "%$iFile%" > "%$oFile%" and should work.