Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new line in text file with Windows batch file

I have a text file which has more than 200 lines in it, and I just want to add a new line before line 4. I'm using Windows XP.

Example text file before input:

header 1 header 2 header 3 details 1 details 2 

After output:

header 1 header 2 header 3 <----- This is new line ----> details 1 details 2 
like image 520
newbie18 Avatar asked Sep 13 '11 04:09

newbie18


People also ask

How do you make a new line in a batch file?

To create a blank line in a batch file, add an open bracket or period immediately after the echo command with no space, as shown below. Adding @echo off at the beginning of the batch file turns off the echo and does not show each of the commands.

How do you add a line to a text file in CMD?

Windows: `Echo` Newline (Line Break) [\n] – CMD & PowerShell. In a Windows Command Prompt (CMD) and PowerShell when you execute the echo command to print some text or redirect it to a file, you can break it into multiple lines. In Linux you can do this by using the \n .

How do I add a new line in CMD?

each time you press enter with a ^ at the end of the line, just press enter again to actually escape/embed a newline.

How do I echo a new line in Windows?

You can insert an invisible ascii chr(255) on a separate line which will force a blank new line. Hold down the [alt] key and press 255 on the keypad. this inserts chr(255) which is a blank square. i.e. "echo (alt+255)" You can only use the keypad not the numbers at the top of the querty keyboard!


1 Answers

I believe you are using the

echo Text >> Example.txt  

function?

If so the answer would be simply adding a "." (Dot) directly after the echo with nothing else there.

Example:

echo Blah echo Blah 2 echo. #New line is added echo Next Blah 
like image 175
avitex Avatar answered Oct 01 '22 03:10

avitex