On Fri, 15 Apr 2005, James Miller wrote:
I tried your perl script and it works really well, Flemming. Thanks for bringing it to my attention. I see it works for all files in a given directory--exactly what I need. Now, in place of something like
Patrick\ Cohen\ \&\ Mosaiques\ Quartet\ -\ Quintet\ For\ Piano\ \&\ Strings\ In\ D\ Major\,\ Op.565\,\ G411\ -.\ Andante\ Come\ Prima.mp3
I get
Patrick_Cohen__and__Mosaiques_Quartet_-_Quintet_For_Piano__and__Strings_In_D_Major._Op.56£¯5._G411_-¥²._Andante_Come_Prima.mp3
--a big step in the right direction. But I'm still getting some wierd characters in there--£¯ and ¥². Are these unicode or something?
To strip or translate characters that can't be printed properly or aren't in your locale `man locale' you can use `tr' [translate] from the command-line, for example translate all non-printable characters with
underscores.
~: tr -sc '![:print:]' '_'
translate a `space' to an underscore
~: tr ' ' '_'
DOS to UNIX newlines:
tr -d '\015' < foo.txt > newfoo.txt
or in combi with other programs..
find . -type d -print | xargs rename 'tr/A-Z/a-z/;'
If your translating filenames, from the command-line in a sequence
of events, make sure you use `read', that will help reading non-ascii data. `man ascii'
~: ls -1 | while read FNAME ; do echo ${FNAME} | tr ' ' '_' ; done
Most GNU/Linux distro's come with a standaard program called `rename' ~: rename -h Usage: rename [-v] perlexpr [filenames]
The Bash shell itself has quite some standard easy & powerfull ways onboard
to achive this, named `parameter expansion': ls -1 *.pdf | while read file ; do ps2ascii $file ${file%%pdf}txt ; done
or..
for file in *.bmp ; do convert $file ${file%.bmp}.png ; done
From the bash manual page:
# remove from end the smallest part from `param' # that equals `word' and returns the remainder as result. ${param%%word}
There are more ways to expand parameters, ${param#word}, ${param##word}, ${foo:+bar}... Just look in the manual page..
To give an example, in combination with find : ~: find . -name '*.jpg' -print | while read file ; do echo "${file%/*}/thumb_${file##*/}" ; done
The unix philosophy is, do one thing and do it good.. Search for `Unix
philosopy' at google to learn more about it. Quite interesting, and will
give some historical insights and understanding on the command-line.
J.
Anyway, I can't reproduce these at the command line. Is there any way your script might be made to catch and replace symbols like these as well (I mean, for someone who knows absolutely nothing about Perl, and precious little about scripting in general)? I have no idea what information these symbols are supposed to be representing. It's probably so inconsequential I don't even need it, so replacing it with virtually any other symbol should suffice. I'd say I've got at least 20 files with such symbols, and more are on the way.
Thanks, James
-- Don't worry Ma'am. We're university students, - we know what we're doing.
- To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.linux-learn.org/faqs