[ale] Problems w/ mv and sed

Stephen Touset stephen at touset.dyndns.org
Mon Dec 23 21:09:10 EST 2002


Even odder...

stephen at ayn stephen $ mkdir temp
stephen at ayn stephen $ cd temp
stephen at ayn temp $ ls
stephen at ayn temp $ touch blah.mp3.OK
stephen at ayn temp $ touch blah2.mp3.OK
stephen at ayn temp $ touch blah3.mp3.OK
stephen at ayn temp $ touch blah3.feh.OK
stephen at ayn temp $ rm blah3.feh.OK 
stephen at ayn temp $ touch blah4.mp3.OK
stephen at ayn temp $ rm blah4.mp3.OK 
stephen at ayn temp $ touch blah4.feh.OK
stephen at ayn temp $ touch blah5.mp3
stephen at ayn temp $ mkdir blah6
stephen at ayn temp $ ls
blah.mp3.OK  blah2.mp3.OK  blah3.mp3.OK  blah4.feh.OK  blah5.mp3  blah6
stephen at ayn temp $ for i in *.OK; do mv $i `echo $i | sed
's/\.OK$/.mp3/'`; done;
stephen at ayn temp $ ls
blah.mp3.mp3  blah2.mp3.mp3  blah3.mp3.mp3  blah4.feh.mp3  blah5.mp3 
blah6
stephen at ayn temp $ rm -r *
stephen at ayn temp $ ls
stephen at ayn temp $ cd .
stephen at ayn temp $ cd ..
stephen at ayn stephen $ rmdir temp
stephen at ayn stephen $ mkdir tepm
stephen at ayn stephen $ rmdir tepm/
stephen at ayn stephen $ mkdir temp
stephen at ayn stephen $ cd temp
stephen at ayn temp $ ls
stephen at ayn temp $ touch file\ 1.mp3.OK
stephen at ayn temp $ touch file\ 2.mp3.OK
stephen at ayn temp $ touch file\ 3.mp3.OK
stephen at ayn temp $ touch file\ 4.feh.OK
stephen at ayn temp $ touch file\ 5.feh   
stephen at ayn temp $ mkdir directory
stephen at ayn temp $ ls
directory      file 2.mp3.OK  file 4.feh.OK
file 1.mp3.OK  file 3.mp3.OK  file 5.feh
stephen at ayn temp $ for FILE in ./*\.OK; do echo mv \"$FILE\" \"`echo
$FILE | sed -e 's/\.OK//'`\" .; done;
mv "./file 1.mp3.OK" "./file 1.mp3" .
mv "./file 2.mp3.OK" "./file 2.mp3" .
mv "./file 3.mp3.OK" "./file 3.mp3" .
mv "./file 4.feh.OK" "./file 4.feh" .
stephen at ayn temp $ ls
directory      file 2.mp3.OK  file 4.feh.OK
file 1.mp3.OK  file 3.mp3.OK  file 5.feh

In other words, if I put in the directory at the end (like it's asking),
the script runs, albeit it does nothing. But the awkward thing is, if
you look at the command that gets run, if the period is removed from it,
it SHOULD work fine. But it doesn't, and causes mv to think you're
trying to move multiple files.

By the way, I think I neglected to mention that the filenames contain
spaces in them. So I'm required to have the spaces escaped or the
filename in quotations. That's where the problem lies.

Stephen Touset

On Mon, 2002-12-23 at 20:49, Stephen Touset wrote:
> I still get
> 
> mv: when moving multiple files, last argument must be a directory
> Try `mv --help' for more information.
> mv: when moving multiple files, last argument must be a directory
> Try `mv --help' for more information.
> mv: when moving multiple files, last argument must be a directory
> Try `mv --help' for more information.
> mv: when moving multiple files, last argument must be a directory
> Try `mv --help' for more information.
> mv: when moving multiple files, last argument must be a directory
> Try `mv --help' for more information.
> 
> Stephen Touset
> 
> On Mon, 2002-12-23 at 20:29, Geoffrey wrote:
> > We just covered something similar to this a few days ago.  Try this:
> > 
> > for fn in *.OK;do
> > 	mv $fn ${fn%.OK}
> > done
> > 
> > Stephen Touset wrote:
> > > I've been busy getting some music on gtk-gnutella, and it evidently
> > > renamed files to $(FILENAME).OK if it's good after completion, or
> > > $(FILENAME).BAD if it's corrupted. This is all fine and dandy, except
> > > XMMS uses the filename to determine whether or not it can play the file.
> > > Not to mention, I'd rather not have an .mp3 collection entirely named
> > > .mp3.OK. So this is a job for sed, right? Well, here's the command I
> > > wrote up, and here's the output:
> > > 
> > > for FILE in ./*\.OK; do mv \"$FILE\" \"`echo $FILE | sed -e
> > > 's/\.OK//'`\"; done;
> > > 
> > > mv: when moving multiple files, last argument must be a directory
> > > Try `mv --help' for more information.
> > > mv: when moving multiple files, last argument must be a directory
> > > Try `mv --help' for more information.
> > > mv: when moving multiple files, last argument must be a directory
> > > Try `mv --help' for more information.
> > > mv: when moving multiple files, last argument must be a directory
> > > Try `mv --help' for more information.
> > > mv: when moving multiple files, last argument must be a directory
> > > Try `mv --help' for more information.
> > > 
> > > etc.
> > > 
> > > However, when I use an echo command within the statement:
> > > 
> > > for FILE in ./*\.OK; do echo mv \"$FILE\" \"`echo $FILE | sed -e
> > > 's/\.OK//'`\"; done;
> > > 
> > > I get:
> > > 
> > > mv "./Boston Pops - Final Fantasy 7 Theme.mp3.OK" "./Boston Pops - Final
> > > Fantasy 7 Theme.mp3"
> > > mv "./Boston Pops - Gone With The WInd - Tara's Theme.mp3.OK" "./Boston
> > > Pops - Gone With The WInd - Tara's Theme.mp3"
> > > 
> > > etc.
> > > 
> > > Which seems to be as it should. Anyone know what might be causing this?
> > > 
> > > Stephen Touset
> > 
> > -- 
> > Until later: Geoffrey		esoteric at 3times25.net
> > 
> > The latest, most widespread virus?  Microsoft end user agreement.
> > Think about it...
> > 
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> 


 This is a digitally signed message part




More information about the Ale mailing list