Hello, can someone help me to make a batch to remove 5 zero's from a txt file lfrom the collum 18 of every line ?
PT DFFT EEW323 000003434434 4kdkfd
thank you
@echo off & setlocal EnableDelayedExpansion for /F "delims=" %%j in ('type "File.txt"') do ( set line=%%j set line=!line:~0,17!!line:~22! echo.!line!>> "File.new" )
Ivo, I get this error
C:\Temp>cscript script.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.C:\Temp\script.vbs(1, 1) Microsoft VBScript compilation error: Invalid character
you know why?
thank you
The script I posted is a batch script and must be suffixed .bat (e.g. mybat.bat), then to execute just type its name mybat. That has nothing to do with VBScript (suffixed .vbs).
IVO gave you a batch, like you requested; not a VBScript, which is what you're treating it as. EDIT: Beaten.
Ivo, Thank you its working
do you think we can complicate it a bit? is it possible to
1. delete all 0 after the line 18
2. until it finds a number that its not a 0
3. add the number of 0's deleted as space at the end of that numberexample
00000000ST34567335 text text text
and do this
ST34567335 tex text text
so it satys all align, because if I remove the 0 and dont add the blank lines it will not be alignthank you
Do you want to mean... line actually is column and using _ for space to be readable
00000000ST34567335 text text textbecomes
ST34567335________ text text text
yes, exactly, I need to remove on column 18 all the 0's until it finds a number and replace all the 0's it have removed by an empty space example: Original File
B170600852000003000000000ST17357186TEST TEST TEST B170600852000000100000000ST17356576TEST TEST TEST 1 test B17060085200000250000000ES100011429TEST TES TEST TEST
Changed FileB1706008520000030 ST17357186TEST TEST TEST B1706008520000001 ST17356576TEST TEST TEST 1 test B1706008520000025 ES100011429TEST TES TEST TEST
if we just remove the 0's it will be unformated because some lines have 7 0's to be removed others have 8 0's to be removed so the only way to align the text should be to add spaces in the same number of the 0's removedthank you
edited by moderator: Added pre tags -Razor2.3
@echo off & setlocal EnableDelayedExpansion > "File.new" for /F "delims=" %%j in ('type "File.txt"') do call :CLEAN %%j exit :CLEAN set line=%* set cnt=0 for /L %%k in (17 1 27) do if "!line:~%%k,1!"=="0" (set /A cnt+=1) else (goto :DONE) :DONE set /A end= %cnt% + 17 if %cnt% gtr 0 ( set filler= for /L %%k in (1 1 %cnt%) do (set filler=!filler! ) set line=%line:~0,17%!filler!!line:~%end%! ) echo.%line%>> "File.new" exit /B
Ivo, it's amazing what can you do,
when I try to run it I saw an issue, do you think you still can help?
the part that we need to remove the 0's is always composed by 18 characters like:
00000000ST17356576
the only change that I need is the number of zeros removed from this part they need to be added at the end of that part as spaces like: ST17356576________ where _ is a space
my initial request didint work because the 0's need to be added at the end
B1706008520000030ST17357186________TEST TEST TEST
thank you so much
sorry, at the end of the part of 18 characters after that it will start test again
Be patient, I shall give you the needed code but now I have to perform an urgent repair on one of my servers.
@echo off & setlocal EnableDelayedExpansion > "File.new" for /F "delims=" %%j in ('type "File.txt"') do call :CLEAN %%j exit :CLEAN set line=%* set cnt=0 for /L %%k in (17 1 34) do if "!line:~%%k,1!"=="0" (set /A cnt+=1) else (goto :DONE) :DONE set /A pos= 17 + %cnt% set /A lgt= 18 - %cnt% if %cnt% gtr 0 ( set filler= for /L %%k in (1 1 %cnt%) do (set filler=!filler! ) set line=%line:~0,17%!line:~%pos%,%lgt%!!filler!%line:~35% ) echo.%line%>> "File.new" exit /B
| « .bat to place specific li... | Delete file based on inpu... » |