LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2004, 08:48 AM   #1
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 355

Rep: Reputation: 32
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)
I have several hundred files like this and I'd rather not to have to fix them all manually. Is there a way of doing this on the command line with regular expressions or such like?

Thanks for your time and have a nice day...
 
Old 11-19-2004, 09:23 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 69
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.
 
Old 11-19-2004, 09:33 AM   #3
meblost
Member
 
Registered: May 2004
Location: At Keyboard
Distribution: Mandrake 10.0, SuSE 9.0
Posts: 114

Rep: Reputation: 15
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.
 
Old 11-19-2004, 10:12 AM   #4
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 355

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by rjlee
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.
Hi, I was using codepages 437,850 under OS/2. I don't think they were "wrong" in the sense that they were correct under OS/2. However, for some reason they don't translate properly to Linux.

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?
 
Old 11-19-2004, 10:52 AM   #5
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 355

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by meblost

for foo in $(find . -type f -maxdepth 1);do mv $foo $(echo $foo | tr A a);done
This looks very useful. However, when I try a somewhat simplifed version of it

Code:
for foo in $(find *.mp3);do mv $foo (echo $foo|tr A a);done
or even

Code:
mv coraz?n.txt (echo coraz?n.mp3|tr A a)
I get an error message: bash: syntax error near unexpected token `('
. Does this work under every shell?
 
Old 11-19-2004, 11:03 AM   #6
scottman
Member
 
Registered: Jul 2004
Location: USA
Distribution: Slackware, FreeBSD, LFS
Posts: 72

Rep: Reputation: 15
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
Or just do a recursive copy if you have multiple directories. This will copy all files inside the parent directory.

Code:
cp -R /mnt/cdrom /destination
Or you could always attempt tab completion if typing out a single name.

edit: woops, sorry, misunderstood the first post, disregard

Last edited by scottman; 11-19-2004 at 11:13 AM.
 
Old 11-19-2004, 01:24 PM   #7
meblost
Member
 
Registered: May 2004
Location: At Keyboard
Distribution: Mandrake 10.0, SuSE 9.0
Posts: 114

Rep: Reputation: 15
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.)
 
Old 11-19-2004, 06:16 PM   #8
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 355

Original Poster
Rep: Reputation: 32
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 corazn 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
`Coraz\242n.mp3' -> `Coraz\242n2.mp3'
However, this does not work:

Code:
mv Coraz?n.mp3 $(echo Coraz?n.mp3 | tr \242 )
Sigh...
 
Old 11-20-2004, 07:35 AM   #9
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 355

Original Poster
Rep: Reputation: 32
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cmd line bittorrent quesiton Jukas Linux - Software 2 10-27-2005 04:55 PM
cmd line send attachment? jedimastermopar Linux - General 2 06-16-2005 01:51 PM
Installing ATI drivers via cmd line MentatMM Linux - Newbie 9 12-09-2003 12:51 AM
Best distro for cmd-line webserver Seft Linux - Newbie 4 11-15-2003 04:32 AM
booting then to cmd line..... Why not to GUI?? Ax787 Linux - Newbie 1 10-28-2003 11:45 AM


All times are GMT -5. The time now is 10:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration