added jaunter scripts and tools.
[feisty_meow.git] / scripts / files / remove_bracket_id.sh
1 #!/bin/bash
2
3 # a handy script for fixing file names imported using second inventory.
4 # the names have a hideous long guid as part of them by default.
5
6 if [ $# -lt 1 ]; then
7   echo "This script requires one or more file names whose names should be fixed."
8   echo "Any GUID junk embedded in the name within brackets will be removed."
9   exit 1
10 fi
11
12 while [ $# -gt 0 ]; do
13   file="$1"; shift
14   newname="$(echo "$file" | sed -e 's/\[[a-z0-9A-Z-]*\]//g' | tr ' ' '_' | tr -d "\~'" | sed -e 's/\([0-9]\)_\./\1./g' )"
15   if [ "$file" != "$newname" ]; then
16     # we've effected a name change, so let's actually do it.
17     echo "moving '$file' => '$newname'  "
18     mv "$file" "$newname"
19   fi
20 done
21