pedz
pedz

Reputation: 2349

What options to xargs will make it work with lines rather than words

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

Answers (1)

jhnc
jhnc

Reputation: 16797

You can replace newlines with nulls:

cat list | tr '\n' '\0' | xargs -0 foo

Upvotes: 1

Related Questions