Reputation: 2349
I want to use xargs
(or similar concept) on lines with spaces. In effect, if the input has
line one
line two
line three
...
and I call xargs
such as cat f | xargs foo
, then I want xargs
to execute foo "line one" "line two" "line three" ...
for as many arguments that fit on a command line.
Currently I do this using the shell such as
cat list | while read f ; do foo $f ; done
but that calls foo
for each line and it would be a bit more efficient if foo
is called with a list rather than just one argument.
The -I
option, as documented, sounds like what I want but in my case (Free BSD), it is calling foo
with only one argument. -L
and -R
don't seem to help.
Upvotes: 0
Views: 194
Reputation: 16797
You can replace newlines with nulls:
cat list | tr '\n' '\0' | xargs -0 foo
Upvotes: 1