File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes unix split command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "unix split command" Watch "unix split command" New topic
Author

unix split command

yuga devi
Greenhorn

Joined: Aug 07, 2008
Posts: 22
Hi,

I am new to unix.

I have the following code to grep the word "System" from my Test.jav and split the output to multiple files of 2 lines each.
My code is :

grep 'System' Test.java | split -l 2
which splits correctly and fill the output in the files from the split command xaa, xab,xac...etc.

I want to have my own name in the produced files like test1,test2,test3 etc.

Please help

--Yug
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


yuga,
just provide your own file name at the end . What does man page says about split ?

yuga devi
Greenhorn

Joined: Aug 07, 2008
Posts: 22
Hi Balu,

Thanks for the reply
I tried providing my own file name:

It seems if we provide a file name in the split command, it assumes as source file name.

I am getting the following:

$ grep 'System' Test.java | split -l 2 sample
split: No such file or directory
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

yuga,

Did you check the man page ? use "-" in place for source file name , and provide your own file name after that.
yuga devi
Greenhorn

Joined: Aug 07, 2008
Posts: 22
Thankyou !!! It worked
yuga devi
Greenhorn

Joined: Aug 07, 2008
Posts: 22
Hi,

Is there any possible solution to get more than 676 files using split command?

I have the following command:

grep 'System' Test.log| split -l -n - sample

The no of lines from the output of the grep command is dynamic and it may exceed thousands.

In this case, i could not give the no of lines [-n] in the split command a constant value since split command produces max of 676 files.

The Test.log is a dynamic file. How to handle this situation?

Please help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unix split command
 
Similar Threads
grep the String under subdirectories - --exclude not working
how to use grep in regular expression java
Editing Environment Variables
Get the exact string - not the entire line using grep
Unix Ksh split command