3

This is my first time doing these things. Basically I am creating a batch file html maker for church songs. This is what I am stuck with:

echo <br> %var17% >>Runfiles\temporary2.txt

Basically var 17 is a line of lyric and I want to add a line break in front of it. I have seperated the template maker into three parts:

  • first half
  • lyrics
  • second half

Here is the code:

@echo off
copy "I:\Build\Files\*.txt"

ren *.txt temp.txt

setlocal ENABLEDELAYEDEXPANSION
set vidx=0
for /F "tokens=*" %%A in (temp.txt) do (
SET /A vidx=!vidx! + 1
set var!vidx!=%%A
)
set var

echo <br> %var17% >>Runfiles\temporary2.txt

TYPE Runfiles\temp1.txt > run.html  
TYPE temp.txt >> run.html
TYPE Runfiles\temp2.txt >> run.html
pause

Temp 1 is the beginning and temp2 is the end, so I have a lyric document and I want to insert a <br> element in front of all of them.

The reason is because I have somewhat 100 songs to process and it takes so long to do it manually.

Alberto De Caro
  • 5,147
  • 9
  • 47
  • 73
kriegy
  • 195
  • 1
  • 3
  • 14
  • You never actually bother to state your problem or question. The title comes close, but you should not rely just on the title. – dbenham Jul 10 '12 at 12:07
  • [Generating html with batch .. escape quotes](https://stackoverflow.com/q/7942330/995714), [using batch echo with special characters](https://stackoverflow.com/q/7308586/995714), [Windows Batch System Info to HTML](https://stackoverflow.com/q/22029285/995714), [How to write an XML tag with double quotes using command prompt echo command](https://stackoverflow.com/q/33015273/995714) – phuclv Sep 29 '18 at 03:06
  • Possible duplicate of [Escape angle brackets in a Windows command prompt](https://stackoverflow.com/questions/251557/escape-angle-brackets-in-a-windows-command-prompt) – phuclv Sep 29 '18 at 03:06

2 Answers2

7
echo ^<br^>

Circumflex is the escape character in DOS/Win command line.

SilverbackNet
  • 2,076
  • 17
  • 29
  • 1
    @dbenham well if you really want to get into the specifics, they do look the same but a _circumflex_ is an accent above a character, while the _caret_ is an individual spacing character by itself. – Eitan T Jul 10 '12 at 12:07
3

SilverbackNet has the correct answer for escaping special characters like < and >. But it might be more convenient to establish a variable containing the HTML tag. Special characters do not need to be escaped if they are quoted or expanded using delayed expansion. The definition uses quotes, and the expansion uses delayed expansion.

Using the variable only becomes an advantage when you need to write the tag in multiple places.

set "br=<br>"
....
echo !br! %var17% >>Runfiles\temporary2.txt
dbenham
  • 127,446
  • 28
  • 251
  • 390