Solved Extract s from a file and output it to multiple files

April 23, 2012 at 03:49:45
Specs: Windows 7
I was wondering if there is a way in batch to extract <html></html> docs from a file and echo them into multiple html files. Please take note that the lines each <html> doc has is not constant.

The file looks like this: output.xml


<?xml version="1.0" encoding="windows-1252"?>
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING2</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING3</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING4</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>

And output should look like:

output1.xml:
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>

output2.xml:
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING2</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>

output3.xml:
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING3</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>

output4.xml:
<html>
<head>
<title>COGNITIVE LINGUISTICS AND SECOND LANGUAGE LEARNING4</title>
<link></link>
</head>
<body>
<h1><a></h1>
<h2></h2>

</p>
<h4>
<em></em>
</h4>
</body>
</html>



See More: Extract s from a file and output it to multiple files

Report •

#1
April 23, 2012 at 04:20:27
✔ Best Answer
@echo off & setlocal enabledelayedexpansion
if defined # set #=
set _=output.xml
set #=0
for /f "tokens=*" %%i in (
%_%
) do (
if /i "%%i"=="</html>" (
>>output!#!.xml echo %%i
set /a #+=1
) else (
>>output!#!.xml echo %%i
)
)

Tony


Report •

#2
April 23, 2012 at 04:44:39
It worked Tony. you rock! thanks for the very big help.

BamboLbi


Report •
Related Solutions


Ask Question