Help Reading 2 tokens / line from each outputting to 1 line
Posted: 07 Jun 2010 11:56
Hi I am trying to read a file in where each line has 3 numbers seperated by a space/tab. and I want to use the first two numbers as input and put some text between them (XML tags) and output to a separate file to a new single line (file.txt):
e.g. this file contains:
1 2 3
12345 45456 0
63432 72356 0
73432 92356 0
XML tag:
(Echo style with ^ escape characters:) ^<commercial start="%%G" end="%%H" /^>
<commercial start=%%1 end=%%2 /^>
The Batch File I tried to write is shown below. I tried a bunch of things but don't know what I did wrong (maybe an environment variable can't contain multiple lines, or a DO (command) can't process multiple lines.
--------------
Mybatch file.bat
--------------
echo OFF
rem count number of lines and add another for loop?
rem set beginning=^<^?xml version="1.0" encoding="utf-8"^?^>
set "LINE= empty"
rem FOR /F "tokens=1,3" %%G IN (weather.txt) DO (set "LINE=%LINE%%MIDDLE%" && set "MIDDLE=%%H %%G" && echo "%MIDDLE% %LINE%")
rem echo Middle = %MIDDLE% Line = %line%
rem set LINE= set MIDDLE= @echo.%middle%
del file.txt
@echo %LINE%>file.txt
ECHO *************************
FOR /F "tokens=1,3" %%G IN (weather.txt) DO (
SET "LINE=%LINE% %%G %%H"
ECHO Test LINE=====%LINE%
)
@ECHO %LINE%>>file.txt
Any help you could give would be appreciated.
e.g. this file contains:
1 2 3
12345 45456 0
63432 72356 0
73432 92356 0
XML tag:
(Echo style with ^ escape characters:) ^<commercial start="%%G" end="%%H" /^>
<commercial start=%%1 end=%%2 /^>
The Batch File I tried to write is shown below. I tried a bunch of things but don't know what I did wrong (maybe an environment variable can't contain multiple lines, or a DO (command) can't process multiple lines.
--------------
Mybatch file.bat
--------------
echo OFF
rem count number of lines and add another for loop?
rem set beginning=^<^?xml version="1.0" encoding="utf-8"^?^>
set "LINE= empty"
rem FOR /F "tokens=1,3" %%G IN (weather.txt) DO (set "LINE=%LINE%%MIDDLE%" && set "MIDDLE=%%H %%G" && echo "%MIDDLE% %LINE%")
rem echo Middle = %MIDDLE% Line = %line%
rem set LINE= set MIDDLE= @echo.%middle%
del file.txt
@echo %LINE%>file.txt
ECHO *************************
FOR /F "tokens=1,3" %%G IN (weather.txt) DO (
SET "LINE=%LINE% %%G %%H"
ECHO Test LINE=====%LINE%
)
@ECHO %LINE%>>file.txt
Any help you could give would be appreciated.