add new line in text file with batch file

September 12, 2011 at 19:25:19
Specs: Windows 7
Hi ALL,

Im new here. I have a text file which has more then 200 lines in it and i just want to add new line before line 4. I'm using window 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



See More: add new line in text file with batch file

Report •

#1
September 13, 2011 at 01:20:53
i get the script from other forum. but im still have problem with the format after processing.

this is my script.
@ECHO OFF
SET origfile="C:\Documents and Settings\user\Desktop\test1\before.txt"
SET tempfile="C:\Documents and Settings\user\Desktop\test1\after.txt"
SET insertbefore=4
FOR /F %%C IN ('FIND /C /V "" ^<%origfile%') DO SET totallines=%%C

<%origfile% (FOR /L %%i IN (1,1,%totallines%) DO (
SETLOCAL EnableDelayedExpansion
SET /P L=
IF %%i==%insertbefore% ECHO(
ECHO(!L!
ENDLOCAL
)
) >%tempfile%
COPY /Y %tempfile% %origfile% >NUL
DEL %tempfile%
pause

this script i save as run1.bat. after running, the format is out of order

original file
header 1<--here got tab delimited format--><--here got tab delimited format-->
header 2<--here got tab delimited format--><--here got tab delimited format-->
header 3<--here got tab delimited format--><--here got tab delimited format-->
details 1
details 2

output:
header 1<--tab delimited is missing--><--tab delimited is missing-->
header 2<--tab delimited is missing--><--tab delimited is missing-->
header 3<--tab delimited is missing--><--tab delimited is missing-->

details 1
details 2


Report •
Related Solutions


Ask Question