Assuming the newlines are just missing, your code does this (both sets of code do basically the same thing, so I'll only describe the first one):
Code: Select all
REM Zeroizes the file whose name is stored in %LocationOffsetNew%
echo|set /p=>%LocationOffsetNew%
REM Sets %cntProject% to 0. I'm not sure why, since you never use this variable.
set cntProject=0
REM Sets %file% to %LocationOffset%. Arguably redundant since neither of these
REM variables changes value from here on.
set file=%LocationOffset%
REM Sets newProjects to 0. Again, totally redundant since we're setting it once
REM in the next line.
set /a newProjects=0
REM Sets %newProjects% to the number of non-blank lines in the file
REM whose name is stored in %file%
for /f %%A in ('type "%file%"^|find "" /v /c') do set /a newProjects=%%A
REM Display this number
ECHO NEWPROJECTSCOUNT %newProjects%
REM Iterates over each line in %LocationOffset%, grabbing the first 8 tokens
REM of a comma-delimited string and storing them in %%A through %%H
FOR /F "tokens=1-8 delims=," %%A IN (%LocationOffset%) DO (
REM Sets %cntProject% to 0 for some reason. Again, we never use this variable.
SET /a cntProject=0
REM Iterates over each line in %MappingFile%, grabbing the first two tokens
REM of a comma-delimited string and storing them in %%Y and %%Z
FOR /F "tokens=1-2 delims=," %%Y IN (%MappingFile%) DO (
REM If %%Y is equal to %%E
IF %%Y==%%E (
REM Echo all tokens from the %LocationOffset% string and the
REM second token from the %MappingFile% string to the
REM %LocationOffsetNew% file. The carets before the commas are
REM unnecessary.
ECHO %%A^,%%B^,%%C^,%%D^,%%E^,%%F^,%%G^,%%H^,%%Z>>%LocationOffsetNew%
)
)
)
They can both be simplified like this:
Code: Select all
for /f %%A in ('find /v /c "" %LocationOffset%') do echo NEWPROJECTSCOUNT %%A
type nul >%LocationOffsetNew%
for /f "tokens=1-8 delims=," %%A in (%LocationOffset%) do (
for /f "tokens=1-2 delims=," %%Y in (%MappingFile%) do (
if "%%Y"=="%%E" (
echo %%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,%%Z >>%LocationOffsetNew%
)
)
)
:: -- Mapping of MP to LocationByCC file --
for /f %%A in ('find /v /c "" %LocationByCC%') do echo NEWPROJECTSCOUNT %%A
type nul >%LocationByCCNew%
for /f "tokens=1-8 delims=," %%A in (%LocationByCC%) do (
for /f "tokens=1-2 delims=," %%Y in (%MappingFile%) do (
if "%%Y"=="%%E" (
echo %%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,%%Z >>%LocationByCCNew%
)
)
)
If I saw some sample data, I could maybe optimize it further.