Using repl.bat to extract text from XML to text



I have used repl.bat to extract some lines from a text file successfully for a number of months. Unfortunately the output has changed to XML and it now has backslashes as delimiters in the XML tag.


Here is what i was using when the output file was this



Job Notes=John Smith 123456 dd/MM/yyyy h:mm:ss PM 654321
File Type=4
Location=3


Code



@echo off
set "input=before.txt"
set "output=after.txt"
findstr /r /i /c:"^Job Notes=" "%input%" |repl ".*=(.*) (\d+) (\d+\/\d+\/\d+) \d+:\d+:\d+ .*" "Name=$1\r\nFile Number=$2\r\nDate=$3" x >"%output%"
findstr /r /i /c:"^File Type=" "%input%" >>"%output%"
findstr /r /i /c:"^Location=" "%input%" >>"%output%"


The ouput is now XML



<job_notes>John Smith\123456\dd/MM/yyyy h:mm:ss PM\654321</job_notes>
<file_type>4</file_type>
<location>3</location>


Not sure if this is the issue but the structure of the XML is



<root>
<job>
<job_notes>xxxxxxx</job_notes>
<file_type>x</file_type>
<location>x</location>
</job>
</root>


Can't get a modified script to work. Not sure if the issue is the structure of the XML file or the delimiters.


Thanks


No comments:

Post a Comment