From e5dad1b82a014273f3f46389fb9434ab40c2688c Mon Sep 17 00:00:00 2001 From: Steve Groom Date: Wed, 24 Nov 2021 15:57:51 +0000 Subject: [PATCH] Bugfix trailing and leading chars Trailing chars unnecessarily was changing all . to - in the file name. "this.file.txt " was renamed to "this-file-txt" Leading chars sed command was too greedy " this file.txt" was renamed to "his file.txt" --- utilities-fix-file-names.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities-fix-file-names.sh b/utilities-fix-file-names.sh index f4baefb..a3c5c56 100644 --- a/utilities-fix-file-names.sh +++ b/utilities-fix-file-names.sh @@ -64,7 +64,7 @@ if [ "$lastChar" == " " ] || [ "$lastChar" == "." ] then name=`basename "$line"` # get the filename we need to change path=`dirname "$line"` # dirname to get the path -fixedname=$(echo "$name" | tr '.' '-' | awk '{sub(/[ \t]+$/, "")};1') # remove/replace the trailing whitespace or period +fixedname=$(echo "$name" | awk '{sub(/[ \t]+$/, "")};1') # remove/replace the trailing whitespace or period mv -f "$line" "$path/$fixedname" # rename the file or folder @@ -86,7 +86,7 @@ while ! [ "$counter" == 0 ]; do line="`sed -n ${counter}p /tmp/fixlead.ffn`" name=`basename "$line"` # get the filename we need to change path=`dirname "$line"` # dirname to get the path -fixedname=`echo $name | sed -e 's/^[ \t]*//'` # sed out the leading whitespace +fixedname=`echo $name | sed -e 's/^[ \t]//'` # sed out the leading whitespace echo "This is the original - $line" echo "This is the fix - $path/$fixedname" mv -f "$line" "$path/$fixedname" # rename the file or folder