platon39
Hi all,
i need a script that removes spaces from a text file, that contains date like below,and replaces with ;
file is :
Code: Select all
39999 1 995 WS PS 28-04-2014 01-05-2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 28-04-2014 01-05-2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
Code: Select all
39999;1;995;WS;PS;28-04-2014;01-05-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
39999;1;995;WS;ZS;28-04-2014;01-05-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
----------------------------
#2 26 Mar 2014 13:56
foxidrive
This is a robust way of replacing spaces with a semicolon - your examples don't seem to match above.
Code: Select all
type "file.txt"|repl " " ";" >"newfile.txt"
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
----------------------------
#3 26 Mar 2014 14:11
platon39
Hi Foxydrive,
i tried but it does not work :
Code: Select all
39999 1 995 WS PS 28-Apr-2014 01-May-2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1;
39999 1 995 WS ZS 28-Apr-2014 01-May-2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 ZG AK 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG PZ 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG ZS 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
Code: Select all
39999;1;995;WS;PS;28-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1;
39999;1;995;WS;ZS;28-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
39999;1;995;ZG;AK;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;995;ZG;PZ;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;995;ZG;ZS;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
#4 26 Mar 2014 14:13
foxidrive
did you download repl.bat?
Are they TAB characters separating the numbers?
It works here with a copy and paste of your text.
Last edited by foxidrive (26 Mar 2014 14:14)
----------------------------
#5 26 Mar 2014 14:35
platon39
Hi Foxy
yes they are tabs, so please give me an utility to replace tabs with space if exists.
Many thanks.
Last edited by platon39 (26 Mar 2014 15:04)
----------------------------
#6 26 Mar 2014 15:05
foxidrive
Try this for tabs.
Code: Select all
type "file.txt"|repl "\t" ";" x >"newfile.txt"
#7 26 Mar 2014 15:18
platon39
Hi Foxy,
is working perfect,
thanks a lot for helping me .
----------------------------
#8 26 Mar 2014 16:08
platon39
Can you also tell me if exists an utility to change the format date ? FOr example, if i have in file
Code: Select all
39999 1 995 WS PS 28/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0
39999 1 995 WS ZS 28/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0
39999 1 995 ZG AK 28/04/2014 01/05/2014 0 1 0 0 1 0 0 1 1 0 0
39999 1 995 ZG PZ 28/04/2014 01/05/2014 0 1 0 0 1 0 0 1 1 0 0
39999 1 995 ZG ZS 28/04/2014 01/05/2014 0 1 0 0 1 0 0 1 1 0 0
Code: Select all
39999 1 995 WS PS 28-Apr-2014 01-May-2014 1 1 1 0 1 0 0 1 1 0 0
39999 1 995 WS ZS 28-Apr-2014 01-May-2014 1 1 1 0 1 0 0 1 1 0 0
39999 1 995 ZG AK 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0
39999 1 995 ZG PZ 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0
39999 1 995 ZG ZS 28-Apr-2014 01-May-2014 0 1 0 0 1 0 0 1 1 0 0
Thanks a lot.
----------------------------
#9 26 Mar 2014 17:34
platon39
Hi, i did it myself :
The script is converting an file copied from a excel ( that is why is putting those tabs), convert tabs to spaces ( thanks foxy drive ) and make a csv file .
So from
Code: Select all
39999 1 996 MO PC 28/08/2014 01/10/2014 1 1 0 0 1 0 0 1 1 0 0 0 0 2 1 1 1
39999 1 996 OG PC 28/08/2014 01/10/2014 1 1 0 0 1 0 0 1 1 0 0 0 0 2 1 1 1
Code: Select all
39999;1;996;MO;PC;28-Aug-2014;01-Oct-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;OG;PC;28-Aug-2014;01-Oct-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;OG;ZS;28-Aug-2014;01-Oct-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;FB;AK;28-Aug-2014;01-Oct-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
39999;1;996;FB;PF;28-Aug-2014;01-Oct-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
Code: Select all
SU_DISPOREA.Skript_preprod_ho_real_IM21022226.csv
Code: Select all
echo off
cls
for /f "tokens=* delims=" %%d in (sudispo.txt) do (
type sudispo.txt|repl "\t" ";" x >"newfile.txt"
gsar -s/ -r- -o "D:\lucru\script\newfile.txt"
)
for /f "tokens=6 delims=;" %%a in (newfile.txt) do (
set var=%%a
set dd=%var:~0,2%
set mm=%var:~3,2%
set yy=%var:~6,4%
echo.%var%
echo %dd%
echo %mm%
echo %yy%
)
for /f "tokens=6 delims=;" %%b in (newfile.txt) do (
rem if "%mm%"=="04" gsar -s"%mm%" -rApr -o "D:\lucru\script\newfile.txt"
if "%mm%"=="01" gsar -s"%mm%" -rJan -o "D:\lucru\script\newfile.txt"
if "%mm%"=="02" gsar -s"%mm%" -rFeb -o "D:\lucru\script\newfile.txt"
if "%mm%"=="03" gsar -s"%mm%" -rMar -o "D:\lucru\script\newfile.txt"
if "%mm%"=="04" gsar -s"%mm%" -rApr -o "D:\lucru\script\newfile.txt"
if "%mm%"=="05" gsar -s"%mm%" -rMay -o "D:\lucru\script\newfile.txt"
if "%mm%"=="06" gsar -s"%mm%" -rJun -o "D:\lucru\script\newfile.txt"
if "%mm%"=="07" gsar -s"%mm%" -rJul -o "D:\lucru\script\newfile.txt"
if "%mm%"=="08" gsar -s"%mm%" -rAug -o "D:\lucru\script\newfile.txt"
if "%mm%"=="09" gsar -s"%mm%" -rSep -o "D:\lucru\script\newfile.txt"
if "%mm%"=="10" gsar -s"%mm%" -rOct -o "D:\lucru\script\newfile.txt"
if "%mm%"=="11" gsar -s"%mm%" -rNov -o "D:\lucru\script\newfile.txt"
if "%mm%"=="12" gsar -s"%mm%" -rDec -o "D:\lucru\script\newfile.txt"
)
set %var%=
for /f "tokens=7 delims=;" %%c in (newfile.txt) do (
set var1=%%c
set dd1=%var1:~0,2%
set mm1=%var1:~3,2%
set yy1=%var1:~6,4%
echo.%var1%
echo %dd1%
echo %mm1%
echo %yy1%
)
for /f "tokens=7 delims=;" %%d in (newfile.txt) do (
rem if "%mm1%"=="05" gsar -s"%mm1%" -rMay -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="01" gsar -s"%mm1%" -rJan -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="02" gsar -s"%mm1%" -rFeb -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="03" gsar -s"%mm1%" -rMar -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="04" gsar -s"%mm1%" -rApr -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="05" gsar -s"%mm1%" -rMay -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="06" gsar -s"%mm1%" -rJun -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="07" gsar -s"%mm1%" -rJul -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="08" gsar -s"%mm1%" -rAug -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="09" gsar -s"%mm1%" -rSep -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="10" gsar -s"%mm1%" -rOct -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="11" gsar -s"%mm1%" -rNov -o "D:\lucru\script\newfile.txt"
if "%mm1%"=="12" gsar -s"%mm1%" -rDec -o "D:\lucru\script\newfile.txt"
)
PAUSE
rem set color 70
ECHO .GENERATING THE .CSV FILE
rem SU_DISPOREA.Skript_preprod_ho_real_IM21022226.csv
echo.---------------Country: eg de_real-------------------------------
set /p country=
echo.-------------------IM---------------------------------------------
set /p ticket=
echo --------------------prod/preprod----------------------------------
set /p medium=
echo. 2>SU_DISPOREA.Skript_%medium%_%country%_%ticket%.csv
copy newfile.txt SU_DISPOREA.Skript_%medium%_%country%_%ticket%.csv
pause
:end
echo.
echo.DONE
echo.Press any key to exit.
pause >nul
ENDLOCAL
The only probem is that if i have
Code: Select all
39999 1 995 WS PS 04/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 04/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
Code: Select all
39999 1 995 WS PS 04/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 04/04/2014 01/05/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999;1;995;WS;PS;Apr-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
39999;1;995;WS;ZS;Apr-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
Thanks
Last edited by platon39 (26 Mar 2014 19:28)
----------------------------
#11 27 Mar 2014 07:08
foxidrive
Try this with your sample file.
Code: Select all
@echo off
type "newfile.txt" |repl "\t" ";" |repl "/01/" "/Jan/" L|repl "/02/" "-Feb-" L|repl "/03/" "-Mar-" L|repl "/04/" "-Apr-" L|repl "/05/" "-May-" L|repl "/06/" "-Jun-" L|repl "/07/" "-Jul-" L|repl "/08/" "-Aug-" L|repl "/09/" "-Sep-" L|repl "/10/" "-Oct-" L|repl "/11/" "-Nov-" L|repl "/12/" "-Dec-" L > "newfile2.txt"
pause
#12 27 Mar 2014 10:38
platon39
If i have
Code: Select all
39999 1 995 WS PS 4/28/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 4/28/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 ZG AK 4/28/2014 5/1/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG PZ 4/28/2014 5/1/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
Code: Select all
39999 1 995 WS PS 28/4/2014 1/5/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 28/4/2014 1/5/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 ZG AK 28/4/2014 1/5/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG PZ 28/4/2014 1/5/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
i found a solution:
Code: Select all
for /f "tokens=6 delims=;" %%c in (newfile6.txt) do (
rem echo. First loop
type "newfile6.txt" | repl "%olddata%" "%newdata%" > "final_file.txt"
)
pause
for /f "tokens=7 delims=;" %%m in (final_file.txt) do (
rem echo. Second loop
type "final_file.txt" | repl "%olddata1%" "%newdata1%" > "final_file2.txt"
)
Code: Select all
39999 1 995 WS PS 4/28/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 4/27/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
Code: Select all
39999 1 995 WS PS 4/28/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 27/4/2014 5/1/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1
So what can i to replace for each date ?
thanks
Last edited by platon39 (27 Mar 2014 17:48)
----------------------------
#13 28 Mar 2014 09:29
platon39
Hi,foxy,
i managed to replace the data, but i have a problem
of i have
Code: Select all
39999 1 995 WS PS 04/28/2014 05/01/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 WS ZS 04/28/2014 05/01/2014 1 1 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1
39999 1 995 ZG AK 04/28/2014 05/01/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG PZ 04/28/2014 05/01/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 995 ZG ZS 04/28/2014 05/01/2014 0 1 0 0 1 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 996 MO PC 04/28/2014 05/01/2014 1 1 0 0 1 0 0 1 1 0 0 0 0 2 1 1 1
39999 1 996 OG PC 04/28/2014 05/01/2014 1 1 0 0 1 0 0 1 1 0 0 0 0 2 1 1 1
39999 1 996 OG ZS 04/28/2014 05/01/2014 1 1 0 0 1 0 0 1 1 0 0 0 0 2 1 1 1
39999 1 996 FB AK 04/28/2014 05/01/2014 1 1 0 0 1 1 0 1 1 0 0 1 1 2 1 1 0
39999 1 996 FB PF 04/29/2014 05/02/2014 1 1 0 0 1 1 0 1 1 0 0 1 1 2 1 1 0
39999 1 996 FI PF 04/29/2014 05/02/2014 1 1 0 0 1 1 0 1 1 0 0 1 1 2 1 1 0
39999 1 996 HB AK 04/29/2014 05/02/2014 1 1 0 0 1 1 0 1 1 0 0 1 1 2 1 1 0
39999 1 996 HB PF 04/29/2014 05/02/2014 1 1 0 0 1 1 0 1 1 0 0 1 1 2 1 1 0
Code: Select all
39999;1;995;WS;PS;28-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
39999;1;995;WS;ZS;28-Apr-2014;01-May-2014;;;1;1;1;0;1;0;0;1;;1;0;0;;1;0;1;;;;;;;;1;1;1
39999;1;995;ZG;AK;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;995;ZG;PZ;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;995;ZG;ZS;28-Apr-2014;01-May-2014;;;0;1;0;0;1;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;996;MO;PC;28-Apr-2014;01-May-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;OG;PC;28-Apr-2014;01-May-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;OG;ZS;28-Apr-2014;01-May-2014;;;1;1;0;0;1;0;0;1;;1;0;0;;0;0;2;;;;;;;;1;1;1
39999;1;996;FB;AK;28-Apr-2014;01-May-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
39999;1;996;FB;PF;04-29-2014;05-Feb-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
39999;1;996;FI;PF;04-29-2014;05-Feb-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
39999;1;996;HB;AK;04-29-2014;05-Feb-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
39999;1;996;HB;PF;04-29-2014;05-Feb-2014;;;1;1;0;0;1;1;0;1;;1;0;0;;1;1;2;;;;;;;;1;1;0
Code: Select all
@echo Off
SetLocal EnableDelayedExpansion
::made By Iuliana::
::
cls
pushd C:\APPS\scripts\tech_corr
rem step 1 convert the data from excel file provided in ticket in format mm/dd/yyyy
rem step 1 copy
type "dispo.txt" |repl "\t" ";" |repl "/" "-" x> "newfile6.txt"
for /f "tokens=6 delims=;" %%a in (newfile6.txt) do (
set var=%%a
set mm=!var:~0,2!
set dd=!var:~3,2!
set yy=!var:~6,4!
set olddata=!mm!-!dd!-!yy!
echo.Old data :!olddata!
set newdata=!dd!-!mm!-!yy!
echo.New data :!newdata!
goto replace
)
:replace
type "newfile6.txt" | repl "!olddata!" "!newdata!" > "final_file.txt"
for /f "tokens=7 delims=;" %%g in (newfile6.txt) do (
set var1=%%g
set mm1=!var1:~0,2!
set dd1=!var1:~3,2!
set yy1=!var1:~6,4!
set olddata1=!mm1!-!dd1!-!yy1!
echo.Old data1 :!olddata1!
set newdata1=!dd1!-!mm1!-!yy1!
echo.New data1 :!newdata1!
goto replace1
)
:replace1
type "final_file.txt" | repl "!olddata1!" "!newdata1!" > "final_file2.txt"
echo.FINAL FILE :
type "final_file2.txt"|repl "-01-" "-Jan-" L|repl "-02-" "-Feb-" L|repl "-03-" "-Mar-" L|repl "-04-" "-Apr-" L|repl "-05-" "-May-" L|repl "-06-" "-Jun-" L|repl "-07-" "-Jul-" L|repl "-08-" "-Aug-" L|repl "-09-" "-Sep-" L|repl "-10-" "-Oct-" L|repl "-11-" "-Nov-" L|repl "-12-" "-Dec-" L > "destination1.txt"
#14 28 Mar 2014 09:45
foxidrive
These lines exit the loops. Just remove them.
goto replace
goto replace1
Last edited by foxidrive (28 Mar 2014 09:46)
----------------------------
#15 28 Mar 2014 10:04
platon39
I removed them, but still the same
i assume i must put a while or something, but i don't have any ideea how
to to that in mys script.
Thanks a lot
Last edited by platon39 (28 Mar 2014 10:22)
----------------------------
#16 28 Mar 2014 10:40
foxidrive
I don't understand exactly what your problem is.
----------------------------
#17 28 Mar 2014 11:00
platon39
Let's say i have file:
Code: Select all
39999 1 8230 WB PL 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 8230 WP AK 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 8230 WP DA 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 12 1 1 1
39999 1 8230 WP PL 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 KO PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 NM PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 TN PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 WP PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 KM AK 04/16/2014 04/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
Code: Select all
39999;1;8230;WB;PL;05-16-2014;05-21-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;8230;WP;AK;05-16-2014;05-21-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;8230;WP;DA;05-16-2014;05-21-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;12;;;;;;;;1;1;1
39999;1;8230;WP;PL;05-16-2014;05-21-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;KO;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;NM;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;TN;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;WP;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;KM;AK;16-Apr-2014;21-Apr-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
Code: Select all
39999;1;8230;WB;PL;16-May-2014;21-May-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;8230;WP;AK;16-May-2014;21-May-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;8230;WP;DA;16-May-2014;21-May-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;12;;;;;;;;1;1;1
39999;1;8230;WP;PL;16-May-2014;21-May-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;KO;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;NM;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;TN;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;WP;PP;16-Apr-2014;21-Apr-2014;;;0;1;0;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
39999;1;994;KM;AK;16-Apr-2014;21-Apr-2014;;;0;1;1;0;0;0;0;1;;1;0;0;;0;0;3;;;;;;;;1;1;1
#18 28 Mar 2014 11:04
foxidrive
Your date code is broken, do you mean?
Yesterday you have a different date format in your source file - why did you change it?
Just change it back to what it was.
Last edited by foxidrive (28 Mar 2014 11:08)
----------------------------
#19 28 Mar 2014 11:14
platon39
try this script with the contain provided today :
create file dispo.txt with the content :
Code: Select all
39999 1 8230 WB PL 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 8230 WP AK 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 8230 WP DA 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 12 1 1 1
39999 1 8230 WP PL 05/16/2014 05/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 KO PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 NM PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 TN PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 WP PP 04/16/2014 04/21/2014 0 1 0 0 0 0 0 1 1 0 0 0 0 3 1 1 1
39999 1 994 KM AK 04/16/2014 04/21/2014 0 1 1 0 0 0 0 1 1 0 0 0 0 3 1 1 1
Code: Select all
@echo Off
SetLocal EnableDelayedExpansion
cls
pushd C:\APPS\scripts\tech_corr
type "dispo.txt" |repl "\t" ";" |repl "/" "-" x> "newfile6.txt"
for /f "tokens=6 delims=;" %%a in (newfile6.txt) do (
set var=%%a
set mm=!var:~0,2!
set dd=!var:~3,2!
set yy=!var:~6,4!
set olddata=!mm!-!dd!-!yy!
echo.Old data :!olddata!
set newdata=!dd!-!mm!-!yy!
echo.New data :!newdata!
type "newfile6.txt" | repl "!olddata!" "!newdata!" > "final_file.txt"
)
for /f "tokens=7 delims=;" %%g in (newfile6.txt) do (
set var1=%%g
set mm1=!var1:~0,2!
set dd1=!var1:~3,2!
set yy1=!var1:~6,4!
set olddata1=!mm1!-!dd1!-!yy1!
echo.Old data1 :!olddata1!
set newdata1=!dd1!-!mm1!-!yy1!
echo.New data1 :!newdata1!
type "final_file.txt" | repl "!olddata1!" "!newdata1!" > "final_file2.txt"
)
echo.FINAL FILE :
type "final_file2.txt"|repl "-01-" "-Jan-" L|repl "-02-" "-Feb-" L|repl "-03-" "-Mar-" L|repl "-04-" "-Apr-" L|repl "-05-" "-May-" L|repl "-06-" "-Jun-" L|repl "-07-" "-Jul-" L|repl "-08-" "-Aug-" L|repl "-09-" "-Sep-" L|repl "-10-" "-Oct-" L|repl "-11-" "-Nov-" L|repl "-12-" "-Dec-" L > "destination1.txt"
ECHO .GENERATING THE .CSV FILE
rem SU_DISPOREA.Skript_preprod_ho_real_IM21022226.csv
echo.---------------Country: eg de_real-------------------------------
set /p country=
echo.-------------------IM---------------------------------------------
set /p ticket=
echo --------------------prod/preprod----------------------------------
set /p medium=
echo. 2>SU_DISPOREA.Skript_%medium%_%country%_%ticket%.csv
copy "destination1.txt" SU_DISPOREA.Skript_%medium%_%country%_%ticket%.csv
----------------------------
#20 28 Mar 2014 11:43
foxidrive
It's a long line but try this:
Code: Select all
@echo Off
cls
rem here put your directory where dispo.txt is
pushd C:\APPS\scripts\tech_corr
type "dispo.txt" |repl "\t" ";" |repl "(.*)(\d\d)\/(\d\d)\/(\d\d\d\d)(.*)" "$1$3-$2-$4$5" |repl "(.*)(\d\d)\/(\d\d)\/(\d\d\d\d)(.*)" "$1$3-$2-$4$5" |repl "-01-" "-Jan-" L|repl "-02-" "-Feb-" L|repl "-03-" "-Mar-" L|repl "-04-" "-Apr-" L|repl "-05-" "-May-" L|repl "-06-" "-Jun-" L|repl "-07-" "-Jul-" L|repl "-08-" "-Aug-" L|repl "-09-" "-Sep-" L|repl "-10-" "-Oct-" L|repl "-11-" "-Nov-" L|repl "-12-" "-Dec-" L > "destination1.txt"
pause
#21 28 Mar 2014 11:52
platon39
it worked,
can you explain me in details of how it function ?
thanks a lot for patience and support.
Last edited by platon39 (28 Mar 2014 12:05)
----------------------------
#22 28 Mar 2014 12:10
foxidrive
That segment reformats the date.
The data is split up into the start of the line (.*) and then two numbers (\d\d) and an / character (which has to be escaped with \ ) and then two numbers (\d\d) and another / and four numbers (\d\d)\d\d) and the end of the line (.*)
Each set of brackets is given a number so there are 5 bracketed terms starting with a $ as in $1 $2 $3 $4 $5
The / characters represented by \/ are lost, and the two terms $2 $3 are swapped, and hyphens are inserted in the same spots where the / were.
This segment is run twice because the 'greedy' nature of the regular expression changes the last match of the nn/nn/nnnn and then running it again changes the remaining match of nn/nn/nnnn (which is the first date).
I hope that is clear enough.
Last edited by foxidrive (28 Mar 2014 12:11)
----------------------------
#23 16 Jul 2021 20:47
Simon Sheppard
REPL.BAT has been superseded by JREPL.BAT