Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split single text file into 3 files 1

Status
Not open for further replies.

andysi

Technical User
Mar 11, 2004
5
US
Hi, I'm looking to write a .bat file which can split a text file with three sections in it (with a blank line between each section) into 3 seperate files (one for each section). The length and content of each section varies but there is always a blank line between each section (2 blank lines total). I've had a look around at batch file help pages but have not found anything that would seem to help. I'm running this from the cmd line in windows XP .
Any hints or direction of where to look for a solution would be much appreciated.
 
Unfortunately bat files don't handle editing of that type
very well. You could do the reverse easily in a bat file.
That is, combine 3 files into one using the copy command.

It would be easier,i would think, to write a small basic
program to handle it. This could be called from a bat file.

Separat.bas
-----------
FI$=command$
if fi$="" then system
open fi$ for input as #1
newfile&=1
open "new1.txt" for output as #2
while not eof(1)
Line input #1,LL$
if LTRIM$(RTRIM$(LL$))="" then
newfile&=newfile&+1
CLOSE #2
open "new"+LTRIM$(STR$(newfile&))+".TXT" for output as #2
else
print #2,LL$
end if
wend
close
(not tested)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top