Rory Durrant
Rory Durrant

Reputation: 121

How to redirect more than one output line into a text file?

At the moment I have

echo ping %id% > 1.bat

But I want to copy more than one line of code into another file.

Any ideas?

Upvotes: 0

Views: 220

Answers (2)

dbenham
dbenham

Reputation: 130919

Option 1 - (same as what Stephan posted)

echo first line >1.bat
echo second line >>1.bat

Option 2

>1.bat (
  echo first line
  echo second line
)

Option 3

call :output >1.bat
exit /b

:output
echo first line
echo second line
exit /b

Options 2 and 3 are significantly faster than option 1 if you are writing lots of output because they only have to open and position the stream pointer once, whereas option 1 must open and position for each line.

Upvotes: 1

Stephan
Stephan

Reputation: 56238

echo first line >1.txt
echo second line >>1.txt
echo third line >>1.txt
...

Upvotes: 1

Related Questions