isacklow wrote:
i ran into a situation at work were i had to change the prefix on a bunch of images. this would normally be an relatively simple to do but people keep insiting on putting spaces in the file names, no matter how many times i keep telling them to only use alpha, numeric, "-" and "_" only. so the trick here was to figure out what had to be quoted and what didn't so the script wouldn't choke when it saw spaces in filenames.
note: this will also work for fixing file extensions.
Code:
#!/bin/bash
for i in *.jpg
do
MATCH="<current prefix/extension>";
REPLACE="<new prefix/extension>";
TARGET=$(echo "$i" | sed -e "s/$MATCH/$REPLACE/")
# this allows you to visually see what files are being modified.
# comment this line out if running from a cronjob
echo "$i";
mv "$i" "$TARGET"
done
exit 0
Hi all, forum noob here

It seems you can just replace ALL offending characters with an underscore...........This might get some of them a bit mad, but just telling them to do something won't work.........Once they see that there beautiful names get mangled, they might get the hint

So try something along the lines of what BrionS suggested, but convert them all to underscores.......Something like this should do the trick
Code:
# Create test file:
:>'Uncle $all\ys "brother".ext'
for file in *.ext; do
mv "$file" $(sed 's|[^[:alnum:]_/.-]|_|g' <<<"$file")
done
The output will be someting like
Code:
Uncle $all\ys "brother".ext ---renamed to---> Uncle__all_ys__brother_.ext
Of course, this might be a bit harsh if you're a soft touch

.........But you can always tone it down by including the characters you want to ALLOW in the regexp part of the sed command........Just make sure the hyphen is the last character before the closing bracket (-]), other wise you might allow a whole range of characters you didn't expect.
Anyway, the idea here is to exclude the characters you don't want to mangle, which is a whole lot easier than trying to figure out what you forgot to include as no-no's...
HTH
---thegeekster