From b3ef5909939d6c7ca70ddda533baa25cb5abb312 Mon Sep 17 00:00:00 2001 From: Dan Levitas Date: Thu, 20 Jun 2024 16:55:07 +0000 Subject: [PATCH] [FIX] Address mulitple special chars in uploaded data --- handler/preprocess.sh | 4 ++-- handler/rename_special_chars.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 handler/rename_special_chars.sh diff --git a/handler/preprocess.sh b/handler/preprocess.sh index 0ca71fa..9baf153 100755 --- a/handler/preprocess.sh +++ b/handler/preprocess.sh @@ -19,8 +19,8 @@ fi root=$1 echo "running preprocess.sh on root folder ${root}" -echo "replace file paths that contain spaces or [@^()] characters" -find $root -depth -name "*[ @^()]*" | parallel --linebuffer -j 6 -execdir rename "'s/[ @^()]/_/g'" "{}" \; +echo "replace file paths that contain space, quotation, or [@^()] characters" +find "$root" -depth -name "*[ @^()]*" -print0 | sort -rz | xargs -0 -n 1 -I {} ./rename_special_chars.sh {} echo "running expand.sh" ./expand.sh $root diff --git a/handler/rename_special_chars.sh b/handler/rename_special_chars.sh new file mode 100755 index 0000000..1f504fe --- /dev/null +++ b/handler/rename_special_chars.sh @@ -0,0 +1,11 @@ +#!/bin/bash +file="$1" +dir=$(dirname "$file") +base=$(basename "$file") +new_base=$(echo "$base" | sed 's/[ @^()]/_/g') +new_file="$dir/$new_base" + +if [[ "$file" != "$new_file" ]]; then + echo "Renaming '$file' to '$new_file'" + mv "$file" "$new_file" +fi