From 053da0928147da04afb4dd2ee06c77810b023a91 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Mon, 30 Apr 2012 09:57:28 -0400 Subject: [PATCH] made this script rock now. fixes a lot of ugly names. still could do some more, like by removing tildes and other junk. --- scripts/files/remove_bracket_id.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/files/remove_bracket_id.sh b/scripts/files/remove_bracket_id.sh index 20a0165e..3d3349f0 100644 --- a/scripts/files/remove_bracket_id.sh +++ b/scripts/files/remove_bracket_id.sh @@ -1,13 +1,21 @@ +#!/bin/bash +# a handy script for fixing file names imported using second inventory. +# the names have a hideous long guid as part of them by default. -file=$1 - -if [ -z "$file" ]; then - echo "need a parameter that's a file to remove the id from the name." - exit 3 +if [ $# -lt 1 ]; then + echo "This script requires one or more file names whose names should be fixed." + echo "Any GUID junk embedded in the name within brackets will be removed." + exit 1 fi -newname="$(echo "$file" | sed -e 's/\([^[ ]*\) \[[a-z0-9A-Z-]*\]/\1/')" - -mv "$file" "$newname" +while [ $# -gt 0 ]; do + file="$1"; shift + newname="$(echo "$file" | sed -e 's/\[[a-z0-9A-Z-]*\]//g' | 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