Kiran Sonawane
asked on
batch file - target file has 3 records and destination file has 4 records
If I execute below batch file then CAAGIndividualsFile.TXT file has 3 records and
temp_CAAGIndividualsFile.T XT file has 4 records, Basically if there is space in record it goes to another line. I want to loop for [CR][LF] not for space. Please find attached file as a input file
temp_CAAGIndividualsFile.T
@echo off
setlocal enabledelayedexpansion
call :StripLastCRLF CAAGIndividualsFile.TXT
goto :eof
:StripLastCRLF
for %%a in ("%~1") do set OutF=%%~dpa\temp_(%%~na).txt
for /f %%a in ('type "%~1" ^| find /v /c ""') do (set TotalLines=%%a)
if exist "%OutF%" del "%OutF%"
set /a LineCount=0
for /f "tokens=1* delims=[]" %%a in ('type "%~1" ^| find /v /n ""') do (
set /a LineCount += 1
echo !TotalLines!
if !LineCount!==!TotalLines! (
>>"%OutF%"<NUL (set /p Dummy=%%b)
) else (
>>"%OutF%" echo.%%b
)
)
goto :eof
CAAGIndividualsFile.TXT
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cross posted there clearly!
If you do have to process this data for some reason then you will have to read the file as a binary / random file which you could do using VBA, VBScript etc.
You will notice just doing
more filename.txt
find /v "" filename.txt
etc. all show the extra line, though
type filename.txt doesn't show it, it does then pass it onto the find command still.
[Edit .... glad I didn't write out a VBScript, Bill got in first anyway]
Steve
If you do have to process this data for some reason then you will have to read the file as a binary / random file which you could do using VBA, VBScript etc.
You will notice just doing
more filename.txt
find /v "" filename.txt
etc. all show the extra line, though
type filename.txt doesn't show it, it does then pass it onto the find command still.
[Edit .... glad I didn't write out a VBScript, Bill got in first anyway]
Steve
ASKER
Thanks everyone...
107 k
105 i
114 r
97 a
110 n
9 " "
0
9 " "
9 " "
9 " "
100 d