Batch script How to add space on a numerical variable -
first of approaches, excuse me if not express myself in english.
i'm debutante in batch , need make script
i articles.txt retrieves document in there many lines. lines of document
"t0047" ;"tuyau 1km";"marque2";"jardinage";"75 000";"promo" "t00747";"tuyau 1m";marque2";"jardinage";"30 000";"promo"
first, have remove quotation marks in file. done with:
@echo off setlocal enabledelayedexpansion /f "delims=" %%a in (articles.txt) ( set a=%%a set a=!a:"=! echo !a! echo !a! >>resultat.txt ) the result
t0047 ;tuyau 1km;marque2;jardinage;75 000;promo t00747;tuyau 1m;marque2;jardinage;30 000;promo
then have perform multiplication on column. this, have problem if space not mutiplication realize made script removes spaces.
@echo off setlocal enabledelayedexpansion /f "delims=; tokens=1-8" %%a in (resultat.txt) ( set a=%%e set a=!a: =! echo %%a;%%b;%%c;%%d;!a!;%%f;%%g;%%h echo %%a;%%b;%%c;%%d;!a!;%%f;%%g;%%h >>resultat2.txt ) the result
t0047 ;tuyau 1km;marque2;jardinage;75000;promo t00747;tuyau 1m;marque2;jardinage;30000;promo
then made multiplication.
@echo off setlocal enabledelayedexpansion /f "delims=; tokens=1-8" %%a in (resultat2.txt) ( set a=%%e :: set /a a=!a!/0.6 set /a a=!a!*16666/10000 echo %%a;%%b;%%c;%%d;!a!;%%f;%%g;%%h echo %%a;%%b;%%c;%%d;!a!;%%f;%%g;%%h >>resultat3.txt ) the result
t0047 ;tuyau 1km;marque2;jardinage;124995;promo t00747;tuyau 1m;marque2;jardinage;49998;promo now, add text after first colomn
set champ2=magasin_1;t /f "delims=; tokens=1,*" %%a in (resultat3.txt) ( echo %%a;%champ2%;%%b echo %%a;%champ2%;%%b >>resultat_final.txt ) the actual result is:
t0047 ;magasin_1;t;tuyau 1km;marque2;jardinage;124995;promo t00747;magasin_1;t;tuyau 1m;marque2;jardinage;49998;promo
now add space figure more readable.
t0047 ;magasin_1;t;tuyau 1km;marque2;jardinage;124 995;promo t00747;magasin_1;t;tuyau 1m;marque2;jardinage;49 998;promo
this way it:
@echo off setlocal enabledelayedexpansion /f "delims=" %%a in (articles.txt) ( set "a=%%a" set a=!a:"=! /f "delims=; tokens=1-8" %%a in ("!a!") ( set /a "g1=%%g*16666/10000" set "g2=" /l %%i in (1,1,3) if defined g1 ( set "g2= !g1:~-3!!g2!" set "g1=!g1:~0,-3! ) echo %%a;%%b;%%c;%%d;%%e;%%f;!g2:~1!;%%h echo %%a;%%b;%%c;%%d;%%e;%%f;!g2:~1!;%%h >> result.txt ) ) articles.txt:
"t0047" ;"magasin_1";"t";"tuyau 1km";"marque2";"jardinage";"75000";"promo" "t00747";"magasin_1";"t";"tuyau 1m";marque2";"jardinage";"30000";"promo" result.txt:
t0047 ;magasin_1;t;tuyau 1km;marque2;jardinage;124 995;promo t00747;magasin_1;t;tuyau 1m;marque2;jardinage;49 998;promo
Comments
Post a Comment