comparison tools/add_num_prefix @ 0:a84c32f131df 1.1.29

Import vendor version
author Peter Gervai <grin@grin.hu>
date Wed, 15 Oct 2008 23:28:56 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a84c32f131df
1 #!/bin/sh
2
3 # Add a numeric prefix starting at $1, incrementing by $2 on $3..$n files
4
5 # (c) 2005 Jérôme SAUTRET <jerome@sautret.org>
6 # This script is distributed under GNU GPL. Ask Stallman for details.
7
8 # $Id: add_num_prefix,v 1.1 2005/08/22 19:58:27 jerome Exp $
9
10 set -o errexit
11 if [ -z "$3" ] ; then
12 cat <<EoF
13 Usage:
14 `basename $0` start step files...
15 Add a numeric prefix starting at 'start', incrementing by 'step' on 'files'.
16 EoF
17 exit 1
18 fi
19
20 set -o nounset
21 min=$1
22 len=`echo $1|wc -c|sed 's/^ *//'`
23 let len=len-1
24 min=`echo $min|sed 's/^0*//'`
25 inc=$2
26 shift 2
27 files="$@"
28
29 i=$min
30 for file in $files
31 do
32 new=`printf "%.${len}d" $i `"_$file"
33 echo "$file -> $new"
34 mv "$file" "$new"
35 let i=i+inc
36 done