Making a batch file start from a specific line of text

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Wolfy
Posts: 2
Joined: 17 Mar 2017 03:36

Making a batch file start from a specific line of text

#1 Post by Wolfy » 17 Mar 2017 03:40

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?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 17 Mar 2017 13:37

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

igor_andreev
Posts: 16
Joined: 25 Feb 2017 12:55
Location: Russia

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

#3 Post by igor_andreev » 17 Mar 2017 14:14

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
)

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

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

#4 Post by ShadowThief » 17 Mar 2017 21:12

Image

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#5 Post by penpen » 18 Mar 2017 06:51

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

Post Reply