first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / files / change_prefix.sh
1 #!/bin/bash
2 # change_prefix: takes all of the files in the current directory starting in $1
3 # and modifies their prefix to be $2.
4
5 if [ $# -lt 2 ]; then
6   echo \
7 "$(basename $0): requires two parameters--the old prefix to look for in this directory"
8   echo "and the new prefix (without dots) to change the prefix to."
9   \exit 2
10 fi
11 for i in *; do
12   if [ ! -z "$(echo $i | sed -n -e "s/^\($1\).*\..*$/\1/p")" ]; then
13     extrabit="$(echo $i | sed -n -e "s/^$1\(.*\)\..*$/\1/p")"
14     suffix="$(echo $i | sed -n -e "s/^$1.*\.\(.*\)$/\1/p")"
15 #echo extrabit is $extrabit
16 #echo suff is $suffix
17     mv "$i" "$2$extrabit.$suffix"
18   fi
19 done