Creating a batch/vbs file to append start and end of paragraph

Ask a question BrianGreen 907Posts Saturday January 17, 2015Registration date ModeratorStatus April 24, 2017 Last seen - Last answered on Jan 2, 2017 at 10:12 AM by yg_be
Hi All,

Anyone want a free virtual beer before the Christmas season starts?

I cant believe how hard I am finding this. What I want to do is (in essence) create a web page from a text file that someone at work has written. At this stage all I want to do is add <p> and </p> to the start and end of every paragraph and for this to be separated with a blank line. So what I want to do is convert this
Text 1
Text 2
Text 3

<p>Text 1</p>

<p>Text 2</p>

<p>Text 3</p>

Simple? I failed dismally, but have a bit of success with this in the following batch file, but its not quite what I want - I would need to edit this a bit to get it to look nice and to remove the first </p> and add a final </p>:

rem **************************
rem ** Set Variables **
rem **************************

SET origfile="C:\Users\Brian\Desktop\Untitled 1.txt"
SET tempfile="C:\Users\Brian\Desktop\Untitled 1 copy.txt"
SET insertbefore=""

rem **************************
rem ** Find number of lines **
rem **************************

FOR /F %%C IN ('FIND /C /V "" ^<%origfile%') DO SET totallines=%%C

rem **************************
rem * Print the new text and save the new file *
rem **************************

<%origfile% (FOR /L %%i IN (1,1,%totallines%) DO (
SETLOCAL EnableDelayedExpansion
SET /P L="</p><p>"
IF %%i==%insertbefore% ECHO(
) >%tempfile%

What this produces is
</p><p>Text 1
</p><p>Text 2
</p><p>Text 3

I hope you can help a weary old men and I will let all contributers all into my virtual pub for beers and a mince pie (it is nearly Christmas!).

See more 
plus moins
Hi, I am proposing this vbs:
Dim textline, fso, f1, F2, aline
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile("C:\data\temp\ccm\input.txt", 1, True)
Set F2 = fso.CreateTextFile("C:\data\temp\ccm\output.txt")
While f1.AtEndOfStream <> True
        aline = f1.Readline        'read in the row
        F2.WriteLine "<p>" & aline & "</p>"
        F2.WriteLine ""
f1.Close 'close the input file
Leave a comment

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!