0

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

1 Answers1

0

The adapted batch file using repl.bat written by dbenham:

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

I used for testing before.xml with following data:

<root>
    <job>
        <job_notes>John Smith\123456\02/06/2014 8:34:27 PM\654321</job_notes>
        <file_type>4</file_type>
        <location>3</location>
    </job>
</root>

File after.txt contains for this input example after execution of the batch file:

Name=John Smith
File Number=123456
Date=02/06/2014
File Type=4
Location=3
Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143