loop works (almost) but I need "nested" output

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
davep
Posts: 24
Joined: 29 May 2008 14:03
Location: Nauf Kakalak

loop works (almost) but I need "nested" output

#1 Post by davep » 29 May 2008 14:48

I hope I phrased that right. This is my fist post; please be gentle.

I'm using a for loop to read one line at a time in my source text file, then using that data to create an xml file. I'm having trouble with blank spaces, and/or indenting, and the equals sign.

Here's an example of a few lines from the source text file:

Code: Select all

00:05:20.346
00:07:22:510
00:08:32.284


And I get those values with for /F %%T in (%file1%) do...

And here's What I'm trying to get for each line in the text file:

Code: Select all

 <Markers>
  <Marker
    Time="%%T"
    Value="%%T"
    GenerateKeyframe="True"
    GenerateThumbnail="False" />


Here's a bit of the batch:

Code: Select all

[snip]

:: start the "nest"

echo ^<Markers^> >> %file3%

:: do the rest

for /F %%T in (%file1%) do (
        for %%A in (
  ^<Marker
    Time="%%T"
    Value="%%T"
    GenerateKeyFrame="True"
    GenerateThumbnail="False" ^/^>
                    ) do echo %%A >> %file3%
)

echo ^<^/Markers^> >> %file3%

[snip]


This generates a line for Time, a line for "%%T", a line for Value, a line for "%%T", etc. Also, I'm losing the "=" and I can't seem to get the "nested" look where <Marker is indented two spaces, and Time, Value, etc are indented four spaces.

Here's a bit of what the target should look like:

Code: Select all

<Markers>  
  <Marker 
   Time="00:03:07.687" 
   Value="00:03:07.687" 
   GenerateKeyFrame="True" 
   GenerateThumbnail="False" />
  <Marker 
   Time="00:07:28.573" 
   Value="00:07:28.573" 
   GenerateKeyFrame="True" 
   GenerateThumbnail="False" />
[snip]
</Markers>


Thanks!

chcfrank
Posts: 10
Joined: 22 May 2008 20:24

Re: loop works (almost) but I need "nested" output

#2 Post by chcfrank » 29 May 2008 20:24

Davep,

Here is my prototype is the command prompt, you should be able to convert it into a script. To print initial spaces, use echo. instead just echo

Code: Select all

c:\>echo ^<Markers^> & for /f %i in (x.txt) do @(echo.  ^Marker & echo.    Time="%i" & echo.    Value="%i" & echo.   GenerateKeyframe="True" & echo.    GenerateThumbnail="False" /^> ) & echo ^</Markers^>


-Frank

davep wrote:I hope I phrased that right. This is my fist post; please be gentle.

I'm using a for loop to read one line at a time in my source text file, then using that data to create an xml file. I'm having trouble with blank spaces, and/or indenting, and the equals sign.

Here's an example of a few lines from the source text file:

Code: Select all

00:05:20.346
00:07:22:510
00:08:32.284


And I get those values with for /F %%T in (%file1%) do...

And here's What I'm trying to get for each line in the text file:

Code: Select all

 <Markers>
  <Marker
    Time="%%T"
    Value="%%T"
    GenerateKeyframe="True"
    GenerateThumbnail="False" />


Here's a bit of the batch:

Code: Select all

[snip]

:: start the "nest"

echo ^<Markers^> >> %file3%

:: do the rest

for /F %%T in (%file1%) do (
        for %%A in (
  ^<Marker
    Time="%%T"
    Value="%%T"
    GenerateKeyFrame="True"
    GenerateThumbnail="False" ^/^>
                    ) do echo %%A >> %file3%
)

echo ^<^/Markers^> >> %file3%

[snip]


This generates a line for Time, a line for "%%T", a line for Value, a line for "%%T", etc. Also, I'm losing the "=" and I can't seem to get the "nested" look where <Marker is indented two spaces, and Time, Value, etc are indented four spaces.

Here's a bit of what the target should look like:

Code: Select all

<Markers>  
  <Marker 
   Time="00:03:07.687" 
   Value="00:03:07.687" 
   GenerateKeyFrame="True" 
   GenerateThumbnail="False" />
  <Marker 
   Time="00:07:28.573" 
   Value="00:07:28.573" 
   GenerateKeyFrame="True" 
   GenerateThumbnail="False" />
[snip]
</Markers>


Thanks!

davep
Posts: 24
Joined: 29 May 2008 14:03
Location: Nauf Kakalak

#3 Post by davep » 29 May 2008 20:42

I'll give it a shot when I get back to the office. Thanks! If I may ask a follow up question, how could I use %%T's line number from the source txt instead of just repeating %%T again? Like so:

Code: Select all

Time="hh:mm:ss:msec"
Value="chapter 1"
...
Time="hh:mm:ss:msec"
Value="chapter 2"
...
Time="hh:mm:ss:msec"
Value="chapter 3"
...

Post Reply