Batchcmd - apply the same command to a bunch of files

Batchcmd is a ruby script which applies the same command to a bunch of files. The name of each input file can be adapted and changed using wild cards in order to produce output files or other names adapted to each input file.

Manual

Batchcmd reads the list of files to which the command should be applied from standard input, the command is given as argument. At each call, the character '@' of the command is replaced by the current filename. The script is called as follows

Usage: batchcmd [OPTIONS] <command>

Options:
-n  print the commands that would be executed, but do not execute them
-v  print version information

For instance, in order to apply 'sort' to all .txt files in the current directory, call:

/bin/ls *.txt | batchcmd sort @

where we used /bin/ls instead of ls in order to avoid let the eventual color codes of ls disturb the commands.

Not all use cases are necessarily that easy. Often, an operation creates on output file whose name depends on the input file. For instance, you might want to convert all gif image files whose name begins with 'foo' to the file format png, which is possible using the @STRIP wildcard in the command. At each call, @STRIP is replaced by the current input filename w/o its file suffix:

/bin/ls foo*.gif | batchcmd convert @ @STRIP.png

More complex wildcards operations are supported:

Wild card Replaced by
@ the current input file
@STRIP the current input file without file extension (equivalent to @[1,.])
@[i,j] the part of the current input file indexed by i and j (indices begin with 1) and
$ is replaced by the position of the last character
. is replaced by the position before the first '.'
@[xxx=yyy] the current input file, where the string xxx is replaced by the string yyy

Examples:

ls orig*.ppm | batchcmd threshold @ result@[5,$]
ls orig*.ppm | batchcmd threshold @ @[orig=result]
ls orig*.ppm | batchcmd convert @ @[5,$].gif

Download

No setup is necessary. Just download the file and put it into a directory which is in the PATH of your shell. Just be sure that the ruby shell is available as /usr/bin/ruby, else create a link or change the first line of the script (see requirements).
tool version date downloadremark
batchcmd 1.02 21.11.2007 httpCurrent stable version

Requirements

Ruby

Batchcmd is ritten in the ruby programming language, so you need to have the ruby runtime package installed. Ruby comes with most Linux distributions. To install it on Fedora or Red Hat distributions type "yum install ruby". Ruby can be downloaded for a wide range of systems here.

Credits

Batchcmd was written by Christian Wolf.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.