script to remove unwanted characters from file names

rbell--- via Lynx-dev <[email protected]>
Newsgroups gmane.comp.web.lynx.devel
Message-ID <[email protected]>
#! /bin/bash

# echo "This script removes metacharacters, including spaces, from file names in the current directory, and converts diacritically-marked characters in the file names to ASCII"

for file in *
do
	NewName=`echo $file | tr -d '[]{}&#,() ;?\"|@' | tr -d \' | sed 's/á/a/g;s/à/a/g;s/ä/a/g;s/â/a/g;s/å/a/g;s/ã/a/g;s/é/e/g;s/è/e/g;s/ë/e/g;s/ê/e/g;s/í/i/g;s/ì/i/g;s/ï/i/g;s/î/i/g;s/ó/o/g;s/ò/o/g;s/ö/o/g;s/ô/o/g;s/õ/o/g;s/ø/o/g;s/ú/u/g;s/ù/u/g;s/ü/u/g;s/û/u/g;s/æ/ae/g;s/ñ/n/g;s/ÿ/y/g;s/ç/c/g;s/ß/ss/g;s/Á/A/g;s/À/A/g;s/Ä/A/g;s/Â/A/g;s/Å/A/g;s/Ã/A/g;s/É/E/g;s/È/E/g;s/Ë/E/g;s/Ê/E/g;s/Í/I/g;s/Ì/I/g;s/Ï/I/g;s/Î/I/g;s/Ó/O/g;s/Ò/O/g;s/Ö/O/g;s/Ô/O/g;s/Õ/O/g;s/Ø/O/g;s/Ú/U/g;s/Ù/U/g;s/Ü/U/g;s/Û/U/g;s/Æ/AE/g;s/Ñ/N/g;s/½/oe/g;s/¼/OE/g'`
	if [ "$file" != $NewName ]
	then
	    mv -n "$file" $NewName
	    echo renamed $file to $NewName
	fi	
done


	If high-bit characters get converted by the mail handler in
this message https://pastebin.com/raw/uenmK06k may work.  It does in
lynx but not in Firefox (Damn Firefox!).  I use ISO-8859-15; ½ and ¼
may come through as 1/2 and 1/4 in other ISO-8859s.

	--restrict-filenames in /etc/yt-dlp.conf may help you too.


russell bell
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.