Help needed- replacing text in files having Newline and double quote

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rahuldos
Posts: 1
Joined: 20 Oct 2016 01:37

Help needed- replacing text in files having Newline and double quote

#1 Post by rahuldos » 20 Oct 2016 01:51

Hi All,

I need to make a small replacement in an XML file using DOS program. There is already a batch file made (REPL.BAT) which does replacements excellently (normal texts without double quotes or newline). However, this isn't working in the mentioned case;


Original Text:
---------------

<?xml version="1.0" encoding="utf-8"?>
<ichicsr lang="en">

Desired Text:
---------------

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ichicsr SYSTEM "http://abc.xyz.com/myxml.dtd">
<ichicsr lang="en">

Code: Select all

@echo off
set sourcepath="C:\PROJECT\CODE_ISSUE\IN_TMP"
set destpath="C:\PROJECT\CODE_ISSUE\XML_IN"
set bkppath="C:\PROJECT\CODE_ISSUE\XML_BKP"

for /r "%sourcepath%" %%a in (*.XML) do (
find "messagetype" <"%%a" >nul && (
   echo processing "%%a"
   type "%%a"|REPL "OLD TEXT WITH DOUBLE QUOTES AND NEWLINE" "NEW TEXT" >"%%a.bkp"
   move /y "%%a.bkp" "%destpath%" >nul
   move /y "%%a" "%bkppath%" >null
 
   echo File "%%~nxa" processed and moved to "%destpath%"
   )
)


Thanks,
Rahul
Last edited by Squashman on 20 Oct 2016 06:46, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help needed- replacing text in files having Newline and double quote

#2 Post by foxidrive » 20 Oct 2016 18:55

rahuldos wrote:I need to make a small replacement in an XML file using DOS program. There is already a batch file made (REPL.BAT) which does replacements excellently


The author of repl.bat has created Jrepl.bat and he is a regular here on Dostips named Dave Benham

Jrepl is an enhanced version of repl and they both handle quotes etc. viewtopic.php?f=3&t=6044

Your question doesn't show the code you were using so I'm not sure why you added it.
Oh, hang on - are you using a literal text replacement ? That uses the /L switch from memory.

You need to use a regular expression with the /M switch in jrepl.bat or the new inc capabilities might do it easily.

And piping "%%a" to repl is an inefficient method if it doesn't have to used.

Post Reply