I have a script s1
that outputs a list of numbers separated with ',' e.g. 1,2,3,4
. Now I want to give these numbers to script s2
as arguments, so that s2 will be run on each of them and output its result in a separate line. For example, if s2 multiplies numbers by two, this would be the result I'm looking for:
2
4
6
8
What I'm doing right now is:
s1 | xargs -d "," | xargs -n1 s2
But I feel like I'm doing it in such a foolish way! So my question is:
What is the proper way of doing it?
My problem with my solution is that it's calling xargs twice and iterating over the input twice which is not reasonable to my eyes of course by means of performance! The answer xargs -d "," -n1
seems nice, but I'm not sure if it's only iterating once. If it does, please verify that in your answer, and I'll accept it. By the way, I'd rather not use Perl since it still is iterating twice and also Perl may not exist on many systems.
s1 | xargs -d "," -n1 s2
– George Udosen Dec 18 '17 at 15:13