Playing with xargs

We use pipes to redirect stdout (standard output) of a command to stdin (standard input) of another command. For example:

cat foo.txt | grep "test"

But, some of the commands accept data as command-line arguments rather than a data stream through stdin (standard input). In that case, we cannot use pipes to supply data through command-line arguments.

We should go for alternate methods. xargs is a command that is very helpful in handling standard input data to the command-line argument conversions. xargs can manipulate stdin and convert to command-line arguments for the specified command. Also xargs can convert any one line or multiple line text input into other formats, such as multiple lines (specified number of columns) or a ...

Get Linux Shell Scripting Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.