annotate tools/add_num_prefix @ 5:e8a9408780ff

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