Tom's Guide | Tom's Hardware | Tom's Games | PC Safety Suite
![]() |
![]() |
![]() |
Comment:
I have been redesigning several old batch files to redirect their output to HTML.
Most of the redirects work fine, but of some not so fine.
Sometime the output adds an extra carriage return between lines, which is fine on some occasions.
The following code snippet is one that produces the extra line(s). I want the extra line after the title, but not after each individual line.
How do I prevent these extra lines?
for /f "delims=" %%a in ('ipconfig /all') do (
echo ^<pre^>^<span style="font-size: 12pt"^>%%a ^</span^>^</pre^> ) >> test.html
+1 | ![]() |
Double carriage returns strike again!
for /f "delims=" %%a in ('ipconfig /all') do ( set line=%%a for /f "tokens=1* delims=]" %%b in ('call echo."%%line:~0,-1%%"^|find /n /v ""') do >>test.htm echo.^<pre^>^<span style="font-size: 12pt"^>%%~c ^</span^>^</pre^> )If you are using delayed expansion you can exchange this:
for /f "tokens=1* delims=]" %%b in ('call echo."%%line:~0,-1%%"^|find /n /v ""') do >>test.htm echo.^<pre^>^<span style="font-size: 12pt"^>%%~c ^</span^>^</pre^>With this:
>>test.htm echo.^<pre^>^<span style="font-size: 12pt"^>!line:~0,-1! ^</span^>^</pre^>
+1 | ![]() |
Hi Judago,
I took another approach. The (ia) is just a file created by ipconfig.
============================
@echo off > newfile & setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in (ia) do (
call :sub1 %%a
echo.!str! >> newfile
)
goto :eof:sub1
set str=%*
goto :eof
=====================================
If at first you don't succeed, you're about average.M2
+1 | ![]() |
Good one M2, didn't think of that, it could be simplified further(special characters allowing):
for /f "delims=" %%a in ('ipconfig /all') do ( call :sub1 %%a ) goto :eof :sub1 >> newfile echo.%* goto :eof
+1 | ![]() |
Pretty slick, Slick.
=====================================
If at first you don't succeed, you're about average.M2
+1 | ![]() |
Thanks! Both code examples are much cleaner. I tested the last posted code and noticed that it introduced a new problem. It removes the blank line separator between the adapter type and the first entry. Is it possible to prevent that removal?
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('ipconfig /all') do (
call :sub1 %%a
)
goto :eof:sub1
echo.^<pre^>^<span style="font-size: 12pt"^>%*^</span^>^</pre^>
goto :eof
+1 | ![]() |
Perhaps:
@ECHO OFF echo ^<pre^>^<span style="font-size: 12pt"^> for /f "delims=" %%a in ('ipconfig /all') do ( call :sub1 %%a ) echo ^</span^>^</pre^> goto :eof :sub1 echo.%* goto :eofIt should also save on bytes.....
+1 | ![]() |
Thanks Judago!!
This is a much cleaner solution.
I noticed that this newer code removes all preformatted tabs. For example, If you have multiple DNS servers configured the tab used to align the server's IPs is removed on the second, third, etc. I also tested this on WINs, Routes, etc. and it produces the same issue.
Is there a way to maintain the preformatted "tabs"?
+1 | ![]() |
I thought I tested that, but your right.....
echo ^<pre^>^<span style="font-size: 12pt"^> for /f "delims=" %%a in ('ipconfig /all') do ( call :sub1 "%%a" ) echo ^</span^>^</pre^> goto :eof :sub1 echo.%~1 goto :eof
+1 | ![]() |
You rock....this worked. I have used the code examples to change several other format issues.
Thanks again
![]() |
problem with multipart/fo...
|
ssl pament gateway integr...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.