This answer and code considering:
1) the bat are and run in same folder where the .csv files are
2) you not need use recursively for look and apply edit the .csv files
3) you also need add the Region Name in first line off all files .csv
4) definitely my English is worse than i thought, and limit to me explain more, sorry!..
If you look for pure bat solution, and if your delimiter is ";", may this can help to do this job for you:
@echo off & setlocal EnableDelayedExpansion && cd /d "%~dp0" && title .\%~nx0
for /f ^tokens^=* %%i in ('%__APPDIR__%where .:*.csv')do (set "_csv=%%~fitmp"
cmd.exe /v/c <nul type nul >"!_csv!" && for /f tokens^=^2^delims^=_ %%z in ('
echo="%%~ni"')do set "_r=Region Name"&& for /f tokens^=*^delims^=^; %%I in ('
type "%%~fi"')do echo=!_r!| find "Region N" >nul && (echo=%%~I;!_r!>>"!_csv!"
set "_r=")||(echo=%%~I;%%~z>>"!_csv!"))&& move/y "!_csv!" "!_csv:~0,-3!" >nul
endlocal & exit /b
- Sample File prod_EU_30.csv Test Layout:
A;B;C;D;E;F;G;H;I;J;K;L;M;N
2;3;3;4;4;5;5;6;6;7;7;8;8;9
.;.;.;.;.;.;.;.;.;.;.;.;.;.
n;n;n;n;n;n;n;n;n;n;n;n;n;n
.;.;.;.;.;.;.;.;.;.;.;.;.;.
6;7;7;8;8;9;9;0;0;1;1;2;2;3
- Sample File prod_EU_30.csv Test Layout Results:
A;B;C;D;E;F;G;H;I;J;K;L;M;N;Region Name
2;3;3;4;4;5;5;6;6;7;7;8;8;9;EU
.;.;.;.;.;.;.;.;.;.;.;.;.;.;EU
n;n;n;n;n;n;n;n;n;n;n;n;n;n;n
.;.;.;.;.;.;.;.;.;.;.;.;.;.;EU
6;7;7;8;8;9;9;0;0;1;1;2;2;3;EU
- Obs.: If your delimiter is not "
;
", replace the correct one
- If you don´t need add "Region Name" in first line, try:
@echo off
setlocal EnableDelayedExpansion & cd/d "%~dp0" && title .\%0
for /f ^tokens^=* %%i in ('%__APPDIR__%where ".:*.csv"')do (
set "_f=%%~fitmp" && for /f tokens^=^2^delims^=_ %%z in ('
echo="%%~ni"')do for /f tokens^=^*^delims^=^; %%I in ('
type "%%~fi"')do echo=%%~I;%%~z>>"!_f!")
move /y "!_f!" "!_f:~0,-3!" >nul
endlocal && exit /b