How to modify sets of filenames on cmd line?
Hi all,
I am in the process of moving a large collection of MP3s from an OS/2 partition. First, I copied them all to CDRs and now I will copy them to my Fedora drive. One hiccup: many of the filenames have accented characters (ie, é, ó, á) and they look like this under Linux: Code:
Cuco Valoy - Coraz?n abierto.mp3 (invalid Unicode) Thanks for your time and have a nice day... |
This problem is probably caused by having the wrong character set on the original OS/2 filesystem; try using the charmap=character-set option in /etc/fstab.
Without knowing which character set you were using, it's difficult to work out what the characters were or should be, so fixing the mount options of your original filesystem is the best place to start. |
If you do know what you need to replace, the tr command will help. You could try something like this:
for foo in $(find . -type f -maxdepth 1);do mv $foo $(echo $foo | tr A a);done This will rename each regular file in the current dir and replace all A's with a's. |
Quote:
I can't find any documentation on using a charmap option either in /etc/fstab or when mounting a CDROM on the command line with mount. Are you sure this is possible? |
Quote:
Code:
for foo in $(find *.mp3);do mv $foo (echo $foo|tr A a);done Code:
mv coraz?n.txt (echo coraz?n.mp3|tr A a) . Does this work under every shell? |
You may have typoed the $ before the ()'s. Other possibilities would be using the * wildcard, or the ? single character substitution. The asterisk matches any and all characters, the ? matches any one character. This would work from the directory with all your mp3s.
Code:
cp ./*.mp3 /destination Code:
cp -R /mnt/cdrom /destination edit: woops, sorry, misunderstood the first post, disregard |
You need
for foo in $(find . -name *.mp3);do mv $foo $(echo $foo|tr A a);done and mv coraz?n.txt $(echo coraz?n.mp3|tr A a) I am using bash. I'm sure the syntax is different for other shells. Also, It might be treating the '?' as a regular expression. Mabye you need to escape the '?' (ie substitute coraz?n.txt with coraz\?n.txt, etc.) |
Well, I can get this to work on a string without accented characters, but I can't get tr to filter the accented characters properly. For example, the ó in the word corazón is represented by an empty box on the command line (and a question mark if I just paste it in here). However, when you copy the file on the command line, the OS represents it with a \242.
Code:
$ cp Coraz?n.mp3 Coraz?n2.mp3 Code:
mv Coraz?n.mp3 $(echo Coraz?n.mp3 | tr \242 ó) |
solved another way
Hi all,
After tinkering with the shell stuff and not getting anywhere, I cobbled together a script in Rexx which does everything I need. The tricky bit was figuring out what exactly the illegal characters are, since Linux represents them all as an empty box on the command line. Well, they turn out to be just plain old ASCII codes. So, using the C2D() function in Rexx, I parse the filenames character by character looking for a buch of values like 130 ("é") and converting them to what Linux displays as the correct character. Probably some similar could be done in Python or Perl or perhaps even a shell script, but I am most familiar with Rexx. Bye for now... |
All times are GMT -5. The time now is 12:30 AM. |