Command Line Utility to split text file by number of lines

  • Thread starter Thread starter dingdongdingding
  • Start date Start date
D

dingdongdingding

Guest
I'm looking for an windows command line utility that can split files

by number of line. Most of them are by bytes... can anyone

recommend ? Thanks.
 
You could write your own or try this:







If you tell me what you want to do, I can do it for you and send

you by email. Send me a sample file and tell me how many lines in

each file and I will do it for you. Make sure the files are text

files not binary files because lines only apply to text files.



hth





dingdongdingding wrote:

>

> I'm looking for an windows command line utility that can split files

> by number of line. Most of them are by bytes... can anyone

> recommend ? Thanks.




--

THE INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY

KIND. LD55ZRA DISCLAIMS ALL WARRANTIES, EITHER EXPRESSED OR

IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND

FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL LD55ZRA

OR ITS ASSOCIATES BE LIABLE FOR ANY DAMAGES WHATSOEVER

INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF

BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF LD55ZRA OR ITS

ASSOCIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH

DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR

LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL

DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.



Copyright LD55ZRA 2010.
 
"dingdongdingding" wrote in message

news:85c44ac3-bb4f-4dbe-a629-c7ea09cd30c0@b33g2000yqc.googlegroups.com...

> I'm looking for an windows command line utility that can split files

> by number of line. Most of them are by bytes... can anyone

> recommend ? Thanks.




Your spec is a little vague but perhaps this batch file will ding the way

you want it to dong:

@echo off

set sName=d:\My Files\My Text File.txt

set iLines=30

echo.

if not exist "%sName%" (

echo File "%sName%" not found

goto :eof

)

set Scr="%temp%\TempVBS.vbs"

set VB=echo^>^>%Scr%

cd 1>nul 2>%Scr%

%VB% Set oFSO = CreateObject("Scripting.FileSystemObject")

%VB% Set oFile = oFSO.OpenTextFile("%sName%")

%VB% aFile = Split(oFile.ReadAll, VbCrLf)

%VB% oFile.Close

%VB% Set oOut1 = oFSO.CreateTextFile("%sName%" ^& ".1",True)

%VB% Set oOut2 = oFSO.CreateTextFile("%sName%" ^& ".2",True)

%VB% if %iLines% ^> ubound(aFile) then iLines = UBound(aFile)+1

%VB% For i = 0 To %iLines%-1

%VB% oOut1.WriteLine aFile(i)

%VB% Next

%VB% oOut1.Close

%VB% If UBound(aFile) ^>= %iLines% Then

%VB% For i = %iLines% To UBound(aFile)

%VB% oOut2.WriteLine aFile(i)

%VB% Next

%VB% End If

%VB% oOut2.Close

cscript //nologo %Scr%

rem del %Scr%

echo Data stored in "%sName%.1" and "%sName%.2"
 
On 05 Apr 2010, dingdongdingding wrote in

microsoft.public.windowsxp.general:



> I'm looking for an windows command line utility that can split files

> by number of line. Most of them are by bytes... can anyone

> recommend ? Thanks.




There are Windows ports of the unix head, tail, and split utilities.

Some combination of those could probably be scripted to do what you

want.
 
Interesting. When I tested this, I got 2 files. 1st one with first n

lines. The 2nd one has the rest of the lines (> n lines insde).



On Apr 6, 5:05 pm, "Pegasus [MVP]" wrote:

> "dingdongdingding" wrote in message

>

> news:85c44ac3-bb4f-4dbe-a629-c7ea09cd30c0@b33g2000yqc.googlegroups.com...

>

> > I'm looking for an windows command line utility that can split files

> > by number of line.  Most of them are by bytes... can anyone

> > recommend ?  Thanks.


>

> Your spec is a little vague but perhaps this batch file will ding the way

> you want it to dong:

> @echo off

> set sName=d:\My Files\My Text File.txt

> set iLines=30

> echo.

> if not exist "%sName%" (

>   echo File "%sName%" not found

>   goto :eof

> )

> set Scr="%temp%\TempVBS.vbs"

> set VB=echo^>^>%Scr%

> cd 1>nul 2>%Scr%

> %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")

> %VB% Set oFile = oFSO.OpenTextFile("%sName%")

> %VB% aFile = Split(oFile.ReadAll, VbCrLf)

> %VB% oFile.Close

> %VB% Set oOut1 = oFSO.CreateTextFile("%sName%" ^& ".1",True)

> %VB% Set oOut2 = oFSO.CreateTextFile("%sName%" ^& ".2",True)

> %VB% if %iLines% ^> ubound(aFile) then iLines = UBound(aFile)+1

> %VB% For i = 0 To %iLines%-1

> %VB%   oOut1.WriteLine aFile(i)

> %VB% Next

> %VB% oOut1.Close

> %VB% If UBound(aFile) ^>= %iLines% Then

> %VB%   For i = %iLines% To UBound(aFile)

> %VB%     oOut2.WriteLine aFile(i)

> %VB%   Next

> %VB% End If

> %VB% oOut2.Close

> cscript //nologo %Scr%

> rem del %Scr%

> echo Data stored in "%sName%.1" and "%sName%.2"
 
Unix has this split command. Can't find the windows equivalent.



On Apr 7, 12:31 am, Nil wrote:

> On 05 Apr 2010, dingdongdingding wrote in

> microsoft.public.windowsxp.general:

>

> > I'm looking for an windows command line utility that can split files

> > by number of line.  Most of them are by bytes... can anyone

> > recommend ?  Thanks.


>

> There are Windows ports of the unix head, tail, and split utilities.

> Some combination of those could probably be scripted to do what you

> want.
 
This is exactly the way I wrote it. As I said, your spec was somewhat vague

and allowed several interpretations.



"dingdongdingding" wrote in message

news:9cc8f67f-8704-4443-98e5-0001876ba705@z6g2000yqz.googlegroups.com...

> Interesting. When I tested this, I got 2 files. 1st one with first n

> lines. The 2nd one has the rest of the lines (> n lines insde).

>

> On Apr 6, 5:05 pm, "Pegasus [MVP]" wrote:

>> "dingdongdingding" wrote in message

>>

>> news:85c44ac3-bb4f-4dbe-a629-c7ea09cd30c0@b33g2000yqc.googlegroups.com...

>>

>> > I'm looking for an windows command line utility that can split files

>> > by number of line. Most of them are by bytes... can anyone

>> > recommend ? Thanks.


>>

>> Your spec is a little vague but perhaps this batch file will ding the way

>> you want it to dong:

>> @echo off

>> set sName=d:\My Files\My Text File.txt

>> set iLines=30

>> echo.

>> if not exist "%sName%" (

>> echo File "%sName%" not found

>> goto :eof

>> )

>> set Scr="%temp%\TempVBS.vbs"

>> set VB=echo^>^>%Scr%

>> cd 1>nul 2>%Scr%

>> %VB% Set oFSO = CreateObject("Scripting.FileSystemObject")

>> %VB% Set oFile = oFSO.OpenTextFile("%sName%")

>> %VB% aFile = Split(oFile.ReadAll, VbCrLf)

>> %VB% oFile.Close

>> %VB% Set oOut1 = oFSO.CreateTextFile("%sName%" ^& ".1",True)

>> %VB% Set oOut2 = oFSO.CreateTextFile("%sName%" ^& ".2",True)

>> %VB% if %iLines% ^> ubound(aFile) then iLines = UBound(aFile)+1

>> %VB% For i = 0 To %iLines%-1

>> %VB% oOut1.WriteLine aFile(i)

>> %VB% Next

>> %VB% oOut1.Close

>> %VB% If UBound(aFile) ^>= %iLines% Then

>> %VB% For i = %iLines% To UBound(aFile)

>> %VB% oOut2.WriteLine aFile(i)

>> %VB% Next

>> %VB% End If

>> %VB% oOut2.Close

>> cscript //nologo %Scr%

>> rem del %Scr%

>> echo Data stored in "%sName%.1" and "%sName%.2"


>
 
Thanks. I think the split from http://openetwork.com/berk.html is good

for me.



Thanks everybody !



On Apr 7, 11:46 pm, Nil wrote:

> On 06 Apr 2010, dingdongdingding wrote

> in microsoft.public.windowsxp.general:

>

> > Unix has this split command.  Can't find the windows equivalent.


>

> Here's two:

>

> http://openetwork.com/berk.html

>

> http://www.softwareonline.org/winxs42.html

>

> I've seen others. It often comes in a bundle with a bunch of other unix

> utilities.
 
Back
Top