i want to split a text file on line count

January 20, 2010 at 10:47:22
Specs: Windows XP
help me out, i have never tired batch programming, its ok if its any program(c,c++)
i need to split a text file if it is more than 2000 lines, basically idea is a file should contain not more than 2000 lines,if my input file is 8000 lines then split it into 4 havin 2k lines in each file,with same name and add _01,_02,_03,_04, if any1 can help me plz send the pgr to XXXXXXXXXX@gmail.com i would really b grateful to u .. : ) thank u

edited by moderator: Removed email address -Razor 2.3


See More: i want to split a text file on line count

Report •


#1
January 20, 2010 at 13:24:22
(not tested)
@echo off & setlocal enabledelayedexpansion
set fnam=big_file
set /a n=-1
:(edit oops! i mangled the following line, correcting...)
for /f "tokens=1* delims=]" %%a in ('find /v /n "" %fnam%') do (
set /a n+=1
set /a n1="n%%2000"
if !n1! equ 0 (
set /a n2=n/2000+1
set n2=0!n2!
set out=!fnam!_!n2:~-2!
)
>>!out! echo.%%b
)

Report •

#2
January 20, 2010 at 14:37:11
help me out, i have never tired batch programming, its ok if its any program(c,c++)
i need to split a text file if it is more than 2000 lines, basically idea is a file should contain not more than 2000 lines,if my input file is 8000 lines then split it into 4 havin 2k lines in each file,with same name and add _01,_02,_03,_04, if any1 can help me plz send the pgr to XXXXXXXXXX@gmail.com i would really b grateful to u .. : ) thank u

What language is this? It vaguely looks like English, but English has punctuation, capitalization, and I'm pretty sure half of those "words" don't exist.


Report •

#3
January 20, 2010 at 18:05:07
it's newspeak! LL. haven't you read Orwell? (oh, 1984 was 26 years ago... well, "oldnewspeak" then, or maybe "texpeak" as used by people who text-msg alot)
just kidding j_e, horsing around...

Report •

Related Solutions

#4
January 21, 2010 at 15:08:00
@ nbrane : u r awesome... thanks a lot,,
u'v been a great help.
i made slight changes to it to suit ma requirements..
it works fine,
thank you :)


Report •

#5
January 21, 2010 at 15:22:52
have a litl problem here, the output that it gives is of unknown format ,since ma input file is some.txt ...the output file
is some.txt_01 which is unknown format.. is thr any way to fix this? plzzzzzz
like the out put file should have file name as some_01.txt
thanx again

Report •

#6
January 23, 2010 at 06:04:35
Just change "some.txt_01" into "some_01.txt" straight in the code itself. If the code is done smartly, you would have to change it on very few locations (ideally : one).

Or you tell Windows to open txt_01 with Notepad ... no big deal, but I would also create TXT files instead of yet another format that would eventually also need the same Notepad.


Report •

#7
January 23, 2010 at 12:58:07
yeah, sorry, my mistake. change/add at top, after:
set fnam=big_file
add foll. line:
for %%z in (%fnam%) do set fbase=%%~nz & set fext=%%~xz

then change this:
set out=!fnam!_!n2:~-2!

to:
set out=!fbase!!n2:~-2!!fext!

let me know...


Report •

#8
January 25, 2010 at 09:43:40
it works perfectly fine.,. thank u ..

Report •


Ask Question