The Joys of xargs: Page 2

Posted September 2, 2008

Juliet Kemp

Juliet Kemp

(Page 2 of 4)

Moving on from find: it can be useful to pipe the contents of a file into xargs as input. So,

xargs -t -n2 diff < diff-files
would take the arguments listed in the file diff-files in groups of 2 and run diff on them. So if the diff-files file consisted of:
sample1 alternate1
sample2 alternate2
then xargs would run:
diff sample1 alternate1
diff sample2 alternate2
This can be a quick way of comparing large numbers of files. (Use -p instead of -t to get a pause after each diff as well as an echo of the command.)

You can also use a listings file and xargs to concatenate the contents of those files:

xargs cat < list-of-files > files-contents
(generate list-of-files using xargs as well!
find . -maxdepth 1 -name '*.tex' | xargs echo > list-of-files
would get all your LaTeX source files in the current directory into one list, ready to be stuck together.)

Page 2 of 4

Previous Page
1 2 3 4
Next Page

0 Comments (click to add your comment)
Comment and Contribute


(Maximum characters: 1200). You have characters left.



IT Management Daily
Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that datamation.com may send you Datamation offers via email, phone and text message, as well as email offers about other products and services that Datamation believes may be of interest to you. Datamation will process your information in accordance with the Quinstreet Privacy Policy.