Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unix split command

 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou !!! It worked
 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic