Really I am looking for assistance from senior members how to read the delimited files.
The code is working for delimiter ~,|,=, # but not for % . can any one has idea what is wrong with this code.
Assistance is really appreciated.
My file a1.dat is:
Code: Select all
COMPID%COMPNAME%ADDRESS%YEAROFESTABLISTMENT
100%XYC%AWER RD%12072018
120%BNM%PQTY RD%12082018
100%XYC%AWER RD%12072018
120%BNM%PQTY RD%12082018
Code: Select all
@echo off
REM setlocal enabledelayedexpansion
GOTO :MAIN
setlocal
:replace
echo 2.1 %~1 %~2
set vdl=%~2
set vln=%~1
echo 2.1.1 %vln% delimite %vdl%
:replace2
for /F "tokens=1*delims=%vdl%" %%q in ("%vln%") do (
echo 2.2 %%q %%r
if .%%r neq . (
set "vln=%%q','%%r"
echo 2.3 !vln!
goto :replace2
)
)
echo 2.4 !vln!
set vln='!vln!'
echo 2.5 !vln!
set "%~3=%vln%"
goto :EOF
:MAIN
set vffname=D:\a1.dat
REM echo !vffname!
set "vtilda=%%"
REM echo !vtilda!
REM echo: FILE SIZE !vsize!
REM echo 1 !vheader!
REM set vheader="!vheader!"
REM echo 2 !vheader!
REM set vheader="!vheader:|=","!"
REM set vheader=!vheader:~=","!
REM echo 3 !vheader!
FOR /F "skip=1 usebackq delims=" %%G IN ("!vffname!") DO (
set "line=%%~G"
REM set "line='!line:|=','!'"
REM echo !line!
setlocal
call :replace "!line!" "!vtilda!" fline
echo 1.2 !fline!
set iline=!fline!
endlocal
)
pause
Required output should be :
Code: Select all
'100','XYC','AWER RD','12072018'
'120','BNM','PQTY RD','12082018'
'100','XYC','AWER RD','12072018'
'120','BNM','PQTY RD','12082018'