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.
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
tool | version | date | download | remark |
batchcmd | 1.02 | 21.11.2007 | http | Current stable version |
Batchcmd was written by Christian Wolf.
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.