To import CSV line where 1st value is blank

October 20, 2012 at 00:45:15
Specs: Windows 7
I need to merge all lines from a csv to other csv through batch scripting, if 1st value in a row of source csv is blank then merging is done from 2nd value.
For eg:
Source CSV:
Name;Roll_No;Class;
ABC;23;3
;22;3

Destination csv it's coming like this:
Name;Roll_No;Class;
ABC;23;3
22;3

so, in second row roll_no value is coming under Name,it should be same as source csv.

Thanks In Advance


See More: To import CSV line where 1st value is blank

Report •


#1
October 20, 2012 at 17:09:08
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1-3 delims=;" %%a in (source.csv) do (
if "%%c" equ "" (set dlm=;& set dlm2=) else (set dlm=&set dlm2=;)
>> result.csv echo !dlm!%%a;%%b!dlm2!%%c
:: debug display {since we all know it will crash and burn like the Hindenburg in a lightning storm}
echo !dlm!%%a;%%b!dlm2!%%c
)

Report •

#2
October 21, 2012 at 20:05:18
:: ===== script starts here ===============
::
:: ALKA.bat 2012-10-20 15:41:39.35
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* eol= " %%a in (my.csv) do (
set S=%%a
set F=!S:~0,1!
if "!F!" equ ";" set S=!S:~1!
echo.!S!
)>> newfile
goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions


Ask Question