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
into
<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>:
@ECHO OFF
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(
ECHO(!L!
ENDLOCAL
)
) >%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!).
I really appreciate thank you messages as a payment for solving issues :o)