Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file write <> to text file

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.

like image 515
kriegy Avatar asked Dec 05 '25 18:12

kriegy


2 Answers

echo ^<br^>

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

like image 145
SilverbackNet Avatar answered Dec 08 '25 12:12

SilverbackNet


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
like image 20
dbenham Avatar answered Dec 08 '25 11:12

dbenham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!