Page 1 of 1

Making a batch file start from a specific line of text

Posted: 17 Mar 2017 03:40
by Wolfy
Hi new poster so go gently with me....

This is probably really simple to someone who know but I'm not that great with batch files.

Anyway I have a customer who sends us files that look like this

F3WTXINVOICES 186 201703101540145050085019607 ENTERPRISE 0000
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="eBIS_simple.xsl"?><biztalk_1 xmlns="urn:schemas-biztalk-org:biztalk/biztalk_1.xml">
<header>
<delivery>

I have a mapping that will convert the file into XML however it wont work with that top line. So I need to ignore it.

Now if they sent it in that manner every time I could do a SKIP and ignore the top line.

However sometimes they don't wrap it so the whole message just comes on line one.

So I need to be able to tell the batch file to just start reading from a specific point, ie <?xml version="1.0" ?> and ignore any previous text.

Hope that makes sense....

Any ideas?

Re: Making a batch file start from a specific line of text

Posted: 17 Mar 2017 13:37
by aGerman
What's your goal? Only removing the non-XML text? Or do you want to parse the XML text in order to read specific values out of it? Because you can't (or at least shouldn't) do that with Batch you could combine both tasks in one hybrid script. Just give a little more information.

Steffen

Re: Making a batch file start from a specific line of text

Posted: 17 Mar 2017 14:14
by igor_andreev

Code: Select all

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS

FOR /F "tokens=1 delims=:" %%A IN ('FINDSTR /N /L /C:"\<?xml version=\"1.0\" ?\>" file.ext') DO SET /A "stringline=%%A"

IF NOT DEFINED stringline (ECHO Oops & EXIT /B)

SET /A "ignore_it=%stringline%-1"

IF "%stringline%" GTR "1" (
 ECHO String found at line %stringline%
 REM Here work
 MORE +%ignore_it% file.ext > newfile.ext
) ELSE (
 ECHO String in the first line
)

Re: Making a batch file start from a specific line of text

Posted: 17 Mar 2017 21:12
by ShadowThief
Image

Re: Making a batch file start from a specific line of text

Posted: 18 Mar 2017 06:51
by penpen
Wolfy wrote:Anyway I have a customer who sends us files that look like this
Which encoding is used to store these files (ANSI, UTF-8, UTF16-LE, ...)?

How big are these files (max value)?


penpen