batch file to remove ; at each line end from txt file

June 21, 2019 at 11:39:37
Specs: Windows 10
I have a txt file which has many lines. Some of these lines end with ; Now How to have a batch file to remove from txt file
the end of line ;

See More: batch file to remove ; at each line end from txt file

Report •

June 21, 2019 at 14:30:13
For speed of answer this post should be in the Programming Forum. I'll flag it up to the moderator who may be prepared to move it there for you.

Always pop back and let us know the outcome - thanks

Report •

June 21, 2019 at 21:21:34
Here's something to start with, but I'm sure it will not be the final solution - there's always some complications:

@echo off & setlocal
for /f "tokens=*" %%a in (xxx) do call :aa "%%a"
goto :eof

set z=%1
set semi=%z:~-2%
if "%semi%" equ ";" (echo %z:~1,-2%) else (echo %z:~1,-1%)
::---------- end batch
not tested, and file content can work havoc with batch parsing. A sample of the file you want to "strip" would be welcome in case it has toxic content (<, >, %, &, ! etc.) Any of these chars make batch handling a nightmare and you should use a better handler, or else leave the dbl quotes for your output and handle that issue later.

Report •

September 17, 2019 at 12:45:38
Just give a try for this batch :

@echo off
Title Replace string into a Variable
Set "InpuFile=Inputfile.txt"
Set "OutPutFile=OutputFile.txt"
If Exist %OutPutFile% Del %OutPutFile%
Setlocal EnableDelayedExpansion

FOR /f "delims=" %%a IN ('Type %InpuFile%') DO (
Set "MyVar1=%%a"
Rem We Replace the variable MyVar1 and we set it to a new on NewVar1
Call :Replace !MyVar1! NewVar1
echo !NewVar1!
echo !NewVar1!>>%OutPutFile%
Pause & Exit
::::::::::::Function Replace:::::::::::::
:Replace <OldVar> <NewVar to Set>
set MyString=%1
set StrToFind=;
set NewStr=
set %2=!MyString:%StrToFind%=%NewStr%!
Exit /b

message edited by Hackoo

Report •
Related Solutions

Ask Question