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?
Making a batch file start from a specific line of text
Moderator: DosItHelp
Re: Making a batch file start from a specific line of text
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
Steffen
-
- Posts: 16
- Joined: 25 Feb 2017 12:55
- Location: Russia
Re: Making a batch file start from a specific line of text
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
)
-
- 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
Which encoding is used to store these files (ANSI, UTF-8, UTF16-LE, ...)?Wolfy wrote:Anyway I have a customer who sends us files that look like this
How big are these files (max value)?
penpen