Program to split stdin to multiple output streams?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Program to split stdin to multiple output streams?
Does anyone know of a program to split stdin into multiple output streams? By "split" I really mean "stripe", where lines are striped accross the output files.
Something like this:
cat file | command 4 1> 1.out 2> 2.out 3> 3.out 4> 4.out
If you just want to split a file into multiple pieces, there is in fact a cmd called 'split' that does that.
If you actually meant something else, please give more context/example.
If you just want to split a file into multiple pieces, there is in fact a cmd called 'split' that does that.
If you actually meant something else, please give more context/example.
Im specifically looking for a way to split the output using a round-robbin approach, similar to a stripe, where each successive line goes to the next file in the sequence.
I can do each output, one at a time by using the awk command with a 'NR%value' to determine which group a record falls into, but it requires multiple passes.
Was looking for a way to split the input into output files so that each output file get's the same number of lines (+- one) to account for odd line counts.
Line 1 -> file 1
Line 2 -> file 2
Line 3 -> file 3
etc...
Line N -> file 1
Line N+1 -> file 2
etc...
I can do each output, one at a time by using the awk command with a 'NRvalue' to determine which group a record falls into, but it requires multiple passes.
No it doesn't. Awk will handle all this in one pass if you direct the print to a filename (as a string) - simply use the modulo result as a suffix for example.
No it doesn't. Awk will handle all this in one pass if you direct the print to a filename (as a string) - simply use the modulo result as a suffix for example.
Can you give me an example? I don't see how to do it in one pass.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.