Copy several lines to new file

Microsoft Windows xp professional w/serv...
April 29, 2010 at 20:02:34
Specs: Microsoft Windows XP Professional, 1.794 GHz / 1023 MB
I want a batch file to move the first 8 lines of master.txt to second.txt and save both files. Second.txt will always be overwritten with the new 8 lines each time the batch is run.

If moving is not possible, then just copy the first 8 lines to second.txt this time, and then overwrite it with the next 8 lines each time I run the batch.

Each line of the file contains several special characters and leading spaces, and some blank lines that must be copied to the new file.



See More: Copy several lines to new file

Report •


#1
April 29, 2010 at 20:54:28
::edlin is easiest, if just using batch:
@goto :10
9,#d
e
:10
copy /y master.txt second.txt
edlin second.txt < %0.bat

Report •

#2
April 30, 2010 at 05:53:56
If #1 does it, great.

Otherwise post enough of them file to see what we're dealing with.


=====================================
Helping others achieve escape felicity

M2


Report •

#3
April 30, 2010 at 08:06:58
Response #1 did half of what I needed to do, but did not get the next 9 lines when I ran the batch the second time. I think it could be promising if I put the edlin commands in separate files and run edlin twice, once on the second.txt to remove everything after the 9th line and once on master.txt to remove the first 9 lines. If this works, it will gradually reduce master.txt by 9 lines at a time to become an empty file. That is OK, since the master.txt file is expendable.


Report •

Related Solutions

#4
April 30, 2010 at 08:22:49
I have tried this with the external edlin command text files and it appears to work well, although it creates a small square character as the last item in the both files. I don't know what it is or how to prevent it. I have tried adding /B when running edlin. Any ideas?

Report •

#5
April 30, 2010 at 11:04:07
Nevermind, that character did not cause any problems and everything works well.

Thank for your help.


Report •

#6
April 30, 2010 at 11:16:32
@echo off > Second.txt & @echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^< master.txt') do (
if %%a leq 8 >> second.txt echo.%%b
if %%a gtr 8 >> newfile echo.%%b
)
move /y newfile master.txt


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question