[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"xyargs" idea

From: Andrew Stubbs
Subject: "xyargs" idea
Date: Sun, 23 Jul 2006 15:01:12 +0100

Hi all,

I have attached a little bash script, named "xyargs", that I have been
using for some time now [1], and have found very useful. However, this
implementation has its limitations, so I thought it might be a nice
idea to implement it properly, and what better way than to make it an
official part of findutils - it would share a good amount of code and
features with xargs.

[1] Actually this is a somewhat cleaned up version which is a little
less tested than the original so I apologise if it has a few issues I
haven't yet noticed. I think it still demonstrates the idea.

So, on to what it does. The basic idea is that is is xargs for
programs that take two filenames, an input and an output - one which
exists, and one which may not (yet) exist. It takes the first name as
input, generates the second according to some rule, then calls the
program with the two names. There are many examples of such programs;
everything from cp to gcc. It also supports programs, such as sed,
which take a file and give output on stdout. It can also allow one or
more files to be altered "in place", via a temporary file (if

It is used in much the same way as xargs, except that the user must
describe how the output filename is related to the input filename.

E.g. Make a .orig file from all .c files:  ls *.c | xyargs -s .orig cp

The '-s' option, in the example, instructs it to add a suffix to the
filename. It is also possible to add a prefix and/or perform a regular
expression substitution (in each case, either on just the filename, or
on the whole pathname). It is also possible to combine multiple

This sort of thing isn't too hard with a combination of sed and xargs
(with -n2), but it is harder to do it that way and it doesn't take
long to come up with an example that is hard (particularly when using
output redirect, or temporary intermediate files).

In addition, the above example may be rewritten: xyargs -s .orig cp *.c

Where xargs is intended solely for situations in which the filenames
come from another tool, or else for situations in which the command
line length is a problem, 'xyargs' is also useful for much smaller
tasks. Hence, I find it useful to allow the list of filenames to be
added to the end (actually this was the original implementation before
it could use stdin, but I still find it useful to keep). If you are
averse to this feature I will understand - it doesn't fit the xargs

For further usage information and examples please refer to the
script's --help message.

This script works quite nicely, but it doesn't support many of the
features that xargs does. It is rather more fussy about the filename
input on stdin. It does not do parallel execution or any of that sort
of thing. These deficiencies are why I have come to the conclusion
that integration into findutils would be good. I also think others
could benefit from such a tool (I'm sure many people must have come up
with similar tools, but I haven't seen one anywhere).

Would this idea be suitable for your project? I would be happy to do
the coding myself. Obviously the interface will need adjustment
because many of the options clash with xargs options it would be
desirable to retain, but we can discuss this.


Andrew Stubbs

Attachment: xyargs
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]