Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

The xargs command supplies arguments to a target command by reformatting the data received through stdin. By default, xargs will execute the echo command. In many respects, the xargs command is similar to the actions performed by the find command's -exec option:

  • Converting multiple lines of input to a single-line output:

Xarg's default echo command can be used to convert multiple-line input to single-line text, like this:

          $ cat example.txt # Example file
          1 2 3 4 5 6 
          7 8 9 10 
          11 12
 
          $ cat example.txt | xargs
          1 2 3 4 5 6 7 8 9 10 11 12
  • Converting single-line into multiple-line output:

The -n argument to xargs limits the number of elements placed on each command line invocation. This recipe splits the input into multiple ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985