John Bachir
John Bachir

Reputation: 22721

How can I use the results of one command to invoke another command multiple times?

I'd like to pipe the multi-line results of command A into command B, invoking command B once for each line of the output of command A. Like xargs but with multiple invocations.

Upvotes: 1

Views: 47

Answers (1)

John1024
John1024

Reputation: 113834

If you want to run command B for each line in the output of command A, use xargs with these options:

A |  xargs -n1 -d'\n' B

Explanation:

  • -d'\n' tells xargs to treat its input one line at a time, rather than the default behavior of dividing the input based on whitespace.

  • -n1 tells xargs to run B once for each line of input as a single argument.

Upvotes: 2

Related Questions