[CentOS] Fixing filenames with directories with spaces in the names

Tue Dec 28 17:28:02 UTC 2010
Jay Leafey <jay.leafey at mindless.com>

Craig White wrote:
> Should be simple and perhaps I'm tired but it's not coming to me.
> 
> In its simplest form...
> 
> for old in `cat "$FILENAME"`;do
>   echo "$old"
>   dirname "$old"
>   new="$(echo $old | sed 's/\*/\-/')"
> done
> 
> I'm trying to take out some stupid Macintosh things - in this case
> filenames with asterisks but I have others like tilde's and probably
> others that I haven't come across.
> 

I found a nice little Perl script named "cmv" that will do all sorts of 
file name transformations along the lines you were discussing.  You can 
get it at http://felix.canids.net/plaintext/cmv

Essentially you pass it a Perl regular expression string and a list of 
files to use the string upon.  If you wanted to replace all occurrences 
whitespace with a single hyphen for the files in a directory:

	cmv 's/\s+/-/g' *

This would find all instances of one or more white space characters and 
replace them with a single hyphen for every file in the current 
directory.  I've used this for about a year now and it has worked great.

Hope that helps!
-- 
Jay Leafey - jay.leafey at mindless.com
Memphis, TN
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5529 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.centos.org/pipermail/centos/attachments/20101228/83c88321/attachment-0005.bin>