From 9b7838e4daba218fe52c800af282fe05d24554a1 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Mon, 30 Apr 2012 10:28:58 -0400 Subject: [PATCH] new script, basically ripping off the bracket fixer. there's a more general way to attack this issue. we kind of want to be able to chain a bunch of name changes together for different purposes. --- scripts/files/spaces_to_underscores.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/files/spaces_to_underscores.sh diff --git a/scripts/files/spaces_to_underscores.sh b/scripts/files/spaces_to_underscores.sh new file mode 100644 index 00000000..ebfbcff6 --- /dev/null +++ b/scripts/files/spaces_to_underscores.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# takes names given to it and replaces any spaces or other gnarly characters with underscores. + +#hmmm: this starts to look like a useful function that the bracket fixer could also use. + +if [ $# -lt 1 ]; then + echo "This script requires one or more file names whose names should be fixed." + echo "Any spaces or single-quote characters will be stripped out in a useful way." + exit 1 +fi + +while [ $# -gt 0 ]; do + file="$1"; shift + newname="$(echo "$file" | tr ' ' '_' | tr -d "'" | sed -e 's/\([0-9]\)_\./\1./g' )" + if [ "$file" != "$newname" ]; then + # we've effected a name change, so let's actually do it. + echo "moving '$file' => '$newname' " + mv "$file" "$newname" + fi +done + -- 2.34.1