Zac Heimgartner
Zac Heimgartner

Reputation: 19

Make a Batch File Separate Words to Different Lines

I am need creating a batch file to take an input and separate the content in different lines to a file.

For example:

Apple Banana Orange

And make the file look like:

Apple
Banana
Orange

Is there a way to do this?

Upvotes: 1

Views: 174

Answers (1)

Reinier Torenbeek
Reinier Torenbeek

Reputation: 17383

You can create a script based on the following to ask for input and write the different items to the file result.txt

@echo off
set /p fruit=Give input:

for %%f in (%fruit%) do (
  echo %%f >> result.txt
)

If result.txt already exists, it will append the new items to the existing file. If you do not want that, then just delete result.txt at the beginning of the script.

You can either enter the input by hand, or take input from a file using something like fruit.bat < input.txt

Upvotes: 3

Related Questions