1
Lets say command1 results an array of 10000 value,
I want to pass this result to command2 in 20 patches, 500 value each.
What I have now
command1 arg $(command2 arg)
1
Lets say command1 results an array of 10000 value,
I want to pass this result to command2 in 20 patches, 500 value each.
What I have now
command1 arg $(command2 arg)
2
You can use xargs
for this purpose:
command2 arg | xargs -n 500 command1
xargs
is a program to build and execute command lines from standard input
.
-n
says each time run the command
with 500 input given from stdin
.To test it:
$ echo `for i in {1..50}; do echo $i; done;` | xargs -n 10 echo
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
That's great, I accepted the answer, Can I make the Command 1 arguments dynamic also? changing with each patch? – iShaalan – 2017-05-18T08:02:52.723
let say command1 is addToFile filename , can I male the filename changes for each patch? – iShaalan – 2017-05-18T08:03:47.330
I'm not sure what you are trying to achieve you want some time run the command with parameter A and sometimes B? – Ravexina – 2017-05-18T08:10:01.457
okay, Command1 creates a file given a filename and array of values, command2 result is 10000 values, I want to have 20 files with different names each having 500 values. What I achieved with your help was writing to the same file 20 times, I want to make the result separated to 20 files – iShaalan – 2017-05-18T08:20:45.333
Please note that I am using the file creation command as an example. – iShaalan – 2017-05-18T08:23:18.767
1unfortunately I think that's not possible, however have a look at
man xargs
and-p
option it might help you. – Ravexina – 2017-05-18T08:32:57.230