Dear all,
glad to be with you!
I started to programm a bat file but now I stucked due to my low skill level.
My files looks like this:
PLS~PLIY ~CEER ~NRS ~RDDOCKUTN ~ENN. GERM ~ROWTERMINAL/RETURNCH ~REVUEDDNO ~VALLI ~PO
1 ~1 ~099999 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
3 ~3 ~054154 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
5 ~5 ~045465 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
2 ~2 ~745454 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
4 ~4 ~412154 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
6 ~6 ~156566 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
3 ~3 ~454654 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
2 ~2 ~546546 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
1 ~1 ~044456 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
and so on...
All Files named as the number of the 2nd token: 099999.txt
What I need is to bring the number of the 2nd token to the first for all rows like this:
PLS ~PLIY~CEER ~NRS ~RDDOCKUTN ~ENN. GERM ~ROWTERMINAL/RETURNCH ~REVUEDDNO ~VALLI ~PO
099999~1 ~099999 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~3 ~054154 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~5 ~045465 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~2 ~745454 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~4 ~412154 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~6 ~156566 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~3 ~454654 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~2 ~546546 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
099999~1 ~044456 ~100000008~REDUCEDPERFRM ~DOCUMENTATION ~3-00-1-00-00-00.99 ~* ~ 3,00~1
I need a loop to do that for all files in folder:
C:\GETMSCHINEDATA\FILES
What I tried to start with:
@echo off
set "txt=099999.txt"
set "temp=output.txt"
for /f "tokens=1-10 delims= " %%a in (%txt%) do echo %%a 099999 >> %temp%
Hope you can help me
Thanks and Brgds
Lenny
Replace Value of Token/Column 1 with loop
Moderator: DosItHelp
-
- Posts: 21
- Joined: 04 Aug 2017 14:20
- Location: France
Re: Replace Value of Token/Column 1 with loop
Hi, does that work for you ?
Code: Select all
@echo off
setlocal enableextensions enableDelayedExpansion
set source=C:\GETMSCHINEDATA\FILES
set temp=%source%\temp0123
cd %source% || goto :eof
if not exist "%temp%" (mkdir "%temp%")
echo. & echo Folder = %source%
echo.
for /f %%A in ('2^>nul dir /b /a-d "*.*"') do (
set /a line=0
echo ==^>^> %%A
for /f "usebackq tokens=1-3,* delims= " %%E in ("%%~A") do (
set /a line+=1
if !line! EQU 1 (echo %%E %%F %%G %%H >> "%temp%\%%~A")
if !line! EQU 2 (
set row=%%G
set chain=!row:~1!
echo !chain!%%F %%G %%H >> "%temp%\%%~A"
)
if !line! GEQ 3 (echo !chain!%%F %%G %%H >> "%temp%\%%~A")
)
move /Y "%temp%\%%~A" "%cd%" > nul
)
rmdir /S /Q "%temp%"
endlocal
echo. & pause
exit
Re: Replace Value of Token/Column 1 with loop
Hi barnabe or however unknown,
thats makes me scared!
I feel traced!
But, who cares!
It works perfect (nothing else expected from a pro who would like to be hidden)
You made my day (lots of days !)
All the best unknown friend
In Honored Glory!
thats makes me scared!
I feel traced!
But, who cares!
It works perfect (nothing else expected from a pro who would like to be hidden)
You made my day (lots of days !)
All the best unknown friend
In Honored Glory!
-
- Posts: 21
- Joined: 04 Aug 2017 14:20
- Location: France
Re: Replace Value of Token/Column 1 with loop
Glad to have helped, dear friend.
I wish you a good day, see you soon maybe.
Best regards from France.
I wish you a good day, see you soon maybe.
Best regards from France.