MLUG: Re: [MLUG] Renaming a bunch of files
Re: [MLUG] Renaming a bunch of files
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Wed, 28 Feb 2001, Stephen Bohm wrote:

> Ok.. it didn't quite work.. even after I found out how to change your code
> to bash shell script:

Sorry.  I was actually working on it before you sent your message and I
have fixed it up.  It's still tcsh.  Even if you don't use tcsh, it's
probably still on your system, and the script will still run.  Just make
it an executable file and see if it works.

When I first wrote it, it was just off the top of my head and I didn't
have time to test it.  It took a while to fix it up because I was having
problems dealing with the use of quotes to cope with the spaces and stuff
in the filenames.  The following script works at least for the exact
filenames you sent earlier.  It should work when (1) the current default
directory has only files in it that you want to rename (no other files)
and (2) the filenames aren't more bizarre than what you already showed me.  
I can't guarantee anything!  So far, this does work.


--------------------------------------------------------------------------
#!/usr/bin/tcsh -f

foreach file ( "`ls -1`" )
set newname = `echo $file | awk -F: '{print $NF}'`
mv "$file" "$newname"
end
--------------------------------------------------------------------------


If you want to translate that to another shell, fine, but you probably
have to change quite a few things.  Every shell has its ideosyncracies.  
I don't think tcsh is any better than some of the others, but I know it a
little because I've been using it for a few years.  It would be
interesting to see how other people would have worked this out.

Regards,

Mike

-- 
Michael B. Miller
University of Missouri--Columbia
http://taxa.psyc.missouri.edu/~mbmiller/

--
To manage your subscription, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/