Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to be able to split an output from a command line that goes into a file. I want either or both of the following ways to split:

  • Split based on file size. If it gets to say 500kb, then create a new file
  • Split based on lines in file. If it gets to 1000 lines, then create a new file

Of course, this also means I need a variable name for the output

This is the command I'm running now:

java -jar "C:\Processors\myProcessor.jar" >> "C:\Processors\myprocessor.log"

Would like 'myprocessor.log' to be split in files accordingly.

share|improve this question
add comment

3 Answers

The split command does exactly what you're after, with options to split on file size or on line count. From the man page:

split - split a file into pieces

Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT is -, read standard input.

...snip...

-b, --bytes=SIZE put SIZE bytes per output file

-l, --lines=NUMBER put NUMBER lines per output file

You can get the split command in the GnuWin32 CoreUtils package for use on a Windows machine.

share|improve this answer
add comment

If you want to do this without modifying myProcessor.jar, then you'll need to post-process the log file. I suspect you could do this within Powershell but it is not immediately apparent to me how. There is nothing in Windows to do this.

share|improve this answer
add comment

i believe what you're trying to do requires writing a script at least (command line only won't help)

for scripting purposes of such i would recommend writing a Ruby script (Ruby is a very powerful and extremely easy to learn language - very friendly). writing a batch file to do it will eat your brains (at least it would mine)

share|improve this answer
    
yeah... but I see no other way. I would have to rewrite all the code. –  elcool Feb 17 '11 at 12:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.