I have this batch file code that I wrote. I would like to read the contents of a text file with all the formatting of each line and convert it to HTML.
I have the part for conversion of the html good, but the batch file to read each line isn't working.
I would like to maintain all the original text in the text file as is, but simply read the entire text file from the for loop and echo each line / text in each line out to an html file for easy display.
my current batch file is:
:: start of batch file
@ECHO OFF
FOR /F "eol=; tokens=*" %%i IN ("C:\irtXMT\irtmwb\irtscanlog.txt\irtscanLog.txt") do echo ^<table border="1" BORDERCOLOR="#000000" CELLPADDING="1" CELLSPACING="1" ^> ^<tr^> ^<td width="80" Align="Left" style="background-color:#89A9FF; font:8pt Arial;" ^> %%o ^</td^> ^</tr^> ^</table^> >>c:\irtXMT\iRTMWB.htm
CD\
cd irtXMT
start irtmwb.htm
pause
:: end of batch file
now, though the output of my .htm file / the HTML display shows fine for now, but the out put of the text to be read shows simply: %0
What I would like help with is to read the entire contents of the log file, irtscanlog.txt per each line as is and output the log file to html.
Can I get some assistance, please?
this is the sample of the irtscanlog.txt:
Scan type: Quick scan
Scan options enabled: Memory | Startup | Registry | File System | Heuristics/Extra | Heuristics/Shuriken | PUP | PUM
Scan options disabled: P2P
Objects scanned: 227653
Time elapsed: 1 minute(s), 45 second(s)
Memory Processes Detected: 0
(No malicious items detected)
Memory Modules Detected: 0
(No malicious items detected)
Registry Keys Detected: 0
(No malicious items detected)
Registry Values Detected: 0
(No malicious items detected)
Registry Data Items Detected: 0
(No malicious items detected)
Folders Detected: 0
(No malicious items detected)
Files Detected: 0
(No malicious items detected)
(end)
Read Text file, entire text and display it to HTML
Moderator: DosItHelp
Re: Read Text file, entire text and display it to HTML
The FOR replaceable parameter placed before ^</td^> must be %%i instead %%o:
I suggest you to use "delims=" instead of "tokens=*", unless you want to eliminate leading/trailing spaces.
Antonio
Code: Select all
:: start of batch file
@ECHO OFF
FOR /F "eol=; tokens=*" %%i IN ("C:\irtXMT\irtmwb\irtscanlog.txt\irtscanLog.txt") do echo ^<table border="1" BORDERCOLOR="#000000" CELLPADDING="1" CELLSPACING="1" ^> ^<tr^> ^<td width="80" Align="Left" style="background-color:#89A9FF; font:8pt Arial;" ^> %%i ^</td^> ^</tr^> ^</table^> >>c:\irtXMT\iRTMWB.htm
CD\
cd irtXMT
start irtmwb.htm
pause
:: end of batch file
I suggest you to use "delims=" instead of "tokens=*", unless you want to eliminate leading/trailing spaces.
Antonio
Re: Read Text file, entire text and display it to HTML
Antonio,
Sir you are incredible, thank you for your time Sir. I apprieciate your help.
you know, I was doing additional research too and I agree with your coding and your suggestion about the use of %%0; I should be using %%i.
after digging further and I also found this too,
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=*" %%i IN (C:\irtXMT\irtmwb\irtscanlog.txt\irtscan.txt) do (
echo ^<table border="1" BORDERCOLOR="#000000" CELLPADDING="1" CELLSPACING="1" ^> ^<tr^> ^<td width="850" Align="Left" style="background-color:#89A9FF; font:8pt Arial;" ^> %%i ^</td^> ^</tr^> ^</table^> >>c:\irtXMT\iRTMWB.htm
endlocal
)
this works too; thank you again, have a Great Weekend Sir!
Sir you are incredible, thank you for your time Sir. I apprieciate your help.
you know, I was doing additional research too and I agree with your coding and your suggestion about the use of %%0; I should be using %%i.
after digging further and I also found this too,
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=*" %%i IN (C:\irtXMT\irtmwb\irtscanlog.txt\irtscan.txt) do (
echo ^<table border="1" BORDERCOLOR="#000000" CELLPADDING="1" CELLSPACING="1" ^> ^<tr^> ^<td width="850" Align="Left" style="background-color:#89A9FF; font:8pt Arial;" ^> %%i ^</td^> ^</tr^> ^</table^> >>c:\irtXMT\iRTMWB.htm
endlocal
)
this works too; thank you again, have a Great Weekend Sir!
Re: Read Text file, entire text and display it to HTML
You have to use %%i because that is your loop variable. What made you think you could use %%o?
You do not want to use "delims=*". You want to use what Aacini told you to use.
You do not want to use "delims=*". You want to use what Aacini told you to use.
Re: Read Text file, entire text and display it to HTML
To option 'tokens' the '*' char has special meaning; return all tokens. But option 'delims' takes it literaly; split on every '*' char.booga73 wrote:Antonio,
Sir you are incredible, thank you for your time Sir. I apprieciate your help.
you know, I was doing additional research too and I agree with your coding and your suggestion about the use of %%0; I should be using %%i.
after digging further and I also found this too,
setlocal enabledelayedexpansion
FOR /F "tokens=* delims=*" %%i IN (C:\irtXMT\irtmwb\irtscanlog.txt\irtscan.txt) do (
echo ^<table border="1" BORDERCOLOR="#000000" CELLPADDING="1" CELLSPACING="1" ^> ^<tr^> ^<td width="850" Align="Left" style="background-color:#89A9FF; font:8pt Arial;" ^> %%i ^</td^> ^</tr^> ^</table^> >>c:\irtXMT\iRTMWB.htm
endlocal
)
this works too; thank you again, have a Great Weekend Sir!
Code: Select all
>for /f "delims=" %? in ("o hell*o") do echo.%?
>echo.o hell*o
o hell*o
>for /f "delims=*" %? in ("o hell*o") do echo.%?
>echo.o hell
o hell
>
Code: Select all
>for /f delims^=^ eol^= %? in ("o hell*o") do echo.%?
>echo.o hell*o
o hell*o
>

Code: Select all
for /f delims^=^ eol^= %%i in (C:\irtXMT\irtmwb\irtscanlog.txt\irtscan.txt) do (...


Re: Read Text file, entire text and display it to HTML
Squashman,
I happened to copy / paste some code from my other work to not "reinvent" code and I litterally forgot the %%0 was still in place which I should have used %%i.
I also, through recommendations removed the "delims=*" parameter from my code.
Thank you Guys - Aacini, Squashman and Ed,.
best regards,
Booga73
I happened to copy / paste some code from my other work to not "reinvent" code and I litterally forgot the %%0 was still in place which I should have used %%i.
I also, through recommendations removed the "delims=*" parameter from my code.
Thank you Guys - Aacini, Squashman and Ed,.
best regards,
Booga73