Craig White
2010-Dec-28 05:03 UTC
[CentOS] Fixing filenames with directories with spaces in the names
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. Anyway, $FILENAME has... /tmp/New Woman In Field/*NEW woman in field.psd /tmp/New Woman In Field/*NEW woman in field 2.eps /tmp/New Woman In Field/*NEW woman in field 2.psd and the echoes are broken with spaces like this (which of course doesn't work)... /tmp/New /tmp /tmp/New Woman . Woman In . In Field/*NEW Field Field/-NEW woman . woman in . in field.psd -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Eduardo Grosclaude
2010-Dec-28 11:01 UTC
[CentOS] Fixing filenames with directories with spaces in the names
On Tue, Dec 28, 2010 at 2:03 AM, Craig White <craigwhite at azapple.com> 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/\*/\-/')" > doneShould be new=$(echo "$old" | sed 's/\*/\-/') -- Eduardo Grosclaude Universidad Nacional del Comahue Neuquen, Argentina
John Doe
2010-Dec-28 11:02 UTC
[CentOS] Fixing filenames with directories with spaces in the names
From: Craig White <craigwhite at azapple.com>> 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. > Anyway, $FILENAME has... > /tmp/New Woman In Field/*NEW woman in field.psd > /tmp/New Woman In Field/*NEW woman in field 2.eps > /tmp/New Woman In Field/*NEW woman in field 2.psd > and the echoes are broken with spaces like this (which of course doesn't > work)...Not sure what you are trying to do (delete or rename or...), but try "while read" instead of for (especially since the cmdline is limited)... Example: cat "$FILENAME" | while read OLD do NEW=$(echo "$OLD" | sed 's/\*/\-/') mv -i "$OLD" "$NEW" done JD
Jay Leafey
2010-Dec-28 17:28 UTC
[CentOS] Fixing filenames with directories with spaces in the names
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-0001.bin>
David G. Miller
2010-Dec-28 19:12 UTC
[CentOS] Fixing filenames with directories with spaces in the names
Craig White <craigwhite at ...> writes:> > 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. > > Anyway, $FILENAME has... > > /tmp/New Woman In Field/*NEW woman in field.psd > /tmp/New Woman In Field/*NEW woman in field 2.eps > /tmp/New Woman In Field/*NEW woman in field 2.psd > > and the echoes are broken with spaces like this (which of course doesn't > work)... > > /tmp/New > /tmp > /tmp/New > Woman > . > Woman > In > . > In > Field/*NEW > Field > Field/-NEW > woman > . > woman > in > . > in > field.psd >I'm more of a c-shell guy but a "for loop" uses white space (either newline or space) as the delimiter. One of the other responses suggested an alternative loop construct. Alternatively, the find command with the appropriate commands in either a script file or just following a -exec. Something like: find . -type f -exec `new = `echo {} | tr [bad chars] [replace]`; mv {} $new; echo "old: {} new: $new" \; The above needs lots of work but this way you don't have to visit each directory. Cheers, Dave Cheers, Dave
Bob Marcan
2010-Dec-31 12:34 UTC
[CentOS] Fixing filenames with directories with spaces in the names
On Mon, 27 Dec 2010 22:03:49 -0700 Craig White <craigwhite at azapple.com> 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.Another way: Installed Packages Name : detox Arch : x86_64 Version : 1.2.0 Release : 2.fc14 Size : 135 k Repo : installed From repo : fedora Summary : Utility to replace problematic characters in file names URL : http://detox.sourceforge.net License : BSD Description : Detox is a utility designed to clean up file names. It replaces difficult to : work with characters, such as spaces, with standard equivalents. It will also : clean up file names with UTF-8 or Latin-1 (or CP-1252) characters in them. BR, Bob