Echo new line in bat file




















I have a text file which has more than lines in it, and I just want to add a new line before line 4. The loop reads lines from the original file one by one and outputs them. The output is redirected to a temporary file. When a certain line is reached, an empty line is output before it. After finishing, the original file is deleted and the temporary one gets assigned the original name. The method has one tiny flaw: if the file ends with an empty line, the result will be the actual number of lines minus one.

Or you can use the New line hack. After a little experimentation I discovered that it is possible to do it without issuing two separate echo commands as described in How can you echo a newline in batch files?

This will insert a CR character. Then type the second line. I think it is not possible. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Is it possible to put a new line character in an echo line in a batch file? Asked 12 years, 2 months ago. Active 4 years, 10 months ago. Viewed 96k times. Improve this question. Peter Mortensen Benj Benj Ahaha, yes, almost the same answer I found — Benj. Add a comment.

Active Oldest Votes. Example: echo Hello echo. Improve this answer. Nulano 6 6 silver badges 22 22 bronze badges. We will consider 2 aspects of printing a new line in batch script. Also, by using EnableDelayedExpansion you can achieve the blank line.

You may need any one of them in different situations. When you are running a series of utilities in a single batch file, you may need to echo a blank line between utility execution to have a clear view of the command prompt. Learn how echo new line in batch file works. Note: The main code is between the REM statement. The two spaces are mandatory.

Output: Hello World.



0コメント

  • 1000 / 1000