Replace characters in file names
|
Original Message
|
Name: coreyhead
Date: March 17, 2004 at 21:37:53 Pacific
Subject: Replace characters in file names OS: RedHat 3AS/Mac OS X 10.3. CPU/Ram: multiple
|
Comment: I need a UNIX command to work on OS X on a Mac. I have a client who upgraded from OS 9 to OS X on her mac. She has a huge number of files with "/" and other special characters. I need to remove these so she can use a file server that doesn't allow for those special characters. Is there a UNIX based script or command to just replace these special characters in the file names without having to specifically call out each of the files individually? THANKS! Corey
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: aigles
Date: March 18, 2004 at 04:17:03 Pacific
|
Reply: (edit)You can do something like this :
# # Rename files in current directory # Chars not alphanumeric or '_' or '.' are # replaced by "_" # for file in * do mv "$file" $(echo "$file" | sed 's/[^A-Za-z0-9_.]/_/g') done Jean-Pierre.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: coreyhead
Date: March 20, 2004 at 18:55:58 Pacific
|
Reply: (edit)OK...I tried this script, but I get "Illegal Variable Name" error. I'm thinking I'm missing something here. My UNIX is not Grade A...more like Grade C. Do I need to change something in this script to match the file names? All the file names are different and titles vary greatly. Thanks in advance for your help! Corey
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: aigles
Date: March 22, 2004 at 00:50:36 Pacific
|
Reply: (edit)Maybe
# # Rename files in current directory # Chars not alphanumeric or '_' or '.' are # replaced by "_" # for file in * do mv "$file" `echo "$file" | sed 's/[^A-Za-z0-9_.]/_/g'` done Jean-Pierre.
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: