user2660141
user2660141

Reputation: 1

Script to delete one alphabet from XML file

I would like to delete one symbol "&" from hundred XML file's regularly. Instead of doing manual work, I want to write a .bat script and to schedule it. so that when this bat script runs, the & symbol from all the XML files has to be deleted by the script.

We have a location say D:\Transfer\, in this location my application will generate XML files regularly. I want to search for the symbol (&) in one line of XML and delete that & symbol from XML.

Can someone please help me to get out from this?

Upvotes: 0

Views: 365

Answers (1)

Endoro
Endoro

Reputation: 37569

try this:

@echo off &setlocal
set "search=&"
set "replace="

FOR %%a IN ("D:\Transfer\*.html") DO call:process "%%~a"
goto:eof

:process
set "textfile=%~1"
set "newfile=%~1.new"
(for /f "delims=" %%i in ('findstr /n "^" "%textfile%"') do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%newfile%"
goto:eof

you can also use sed for this:

for %%a in (*.html) do sed "y/&/ /" "%%~a" > "%%~na.new"

Upvotes: 1

Related Questions