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
On Tue, Dec 28, 2010 at 2:03 AM, Craig White craigwhite@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
Should be new=$(echo "$old" | sed 's/*/-/')
From: Craig White craigwhite@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
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!
Craig White <craigwhite@...> 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
On Mon, 27 Dec 2010 22:03:49 -0700 Craig White craigwhite@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