From 6251aae5550ae4f3341494c7bc2d4e87d7d1f807 Mon Sep 17 00:00:00 2001 From: Simon Rieger Date: Thu, 16 Mar 2023 11:56:02 +0000 Subject: [PATCH] add script to replace special characters --- rename-filesh-with-special_characters.sh | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 rename-filesh-with-special_characters.sh diff --git a/rename-filesh-with-special_characters.sh b/rename-filesh-with-special_characters.sh new file mode 100644 index 0000000..798d185 --- /dev/null +++ b/rename-filesh-with-special_characters.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +for file in ./* +do + infile=`echo "${file:2}"|sed \ + -e 's|"\"|"\\"|g' \ + -e 's| |\ |g' -e 's|!|\!|g' \ + -e 's|@|\@|g' -e 's|*|\*|g' \ + -e 's|&|\&|g' -e 's|]|\]|g' \ + -e 's|}|\}|g' -e 's|"|\"|g' \ + -e 's|,|\,|g' -e 's|?|\?|g' \ + -e 's|=|\=|g' ` + outfileNOSPECIALS=`echo "${file:2}"|sed -e 's|[^A-Za-z0-9._-]|_|g'` + outfileNOoe=`echo $outfileNOSPECIALS| sed -e 's|ö|oe|g'` + outfileNOae=`echo $outfileNOoe| sed -e 's|ä|ae|g'` + outfileNOue=`echo $outfileNOae| sed -e 's|ü|ue|g'` + outfileNOOE=`echo $outfileNOue| sed -e 's|Ö|OE|g'` + outfileNOAE=`echo $outfileNOOE| sed -e 's|Ä|AE|g'` + outfileNOUE=`echo $outfileNOAE| sed -e 's|Ü|UE|g'` + outfileNOss=`echo $outfileNOUE| sed -e 's|ß|ss|g'` + outfile=${outfileNOss} + if [ "$infile" != "${outfile}" ] + then + echo "filename changed for " $infile " in " $outfile + mv "$infile" ${outfile} + fi +done + +exit