Re: rename files

From: William Park (opengeometry_at_yahoo.ca)
Date: 09/08/04


Date: 8 Sep 2004 19:02:49 GMT

In <comp.unix.shell> d0x <dan@no.spam> wrote:
> can any one help me out with this. I know somebody must have done it
> already.
>
> i have a directory with 901 files in it.
> i need a script the renames the files. basically i need it to take
> anything that is not a number,letter, or "." and change it to an "_".
>
> ie. "Charlie's Root.zip" - will become "Charlie_s_Root.zip"
>
>
> perl/sh/bash, whatever, dosn't matter. :)

Assuming there is no leading/trailing whitespaces or newlines,
    /bin/ls -d *[^a-zA-Z0-9_]* | while read i;
        j=${i//[^a-zA-Z0-9_]/_}
        mv "$i" "$j"
    done

-- 
William Park <opengeometry@yahoo.ca>
Open Geometry Consulting, Toronto, Canada


Relevant Pages

  • Re: same domain names co-exist in WAN
    ... > This next script renames the account as well as resets the password. ... > 'Rename Local Admin Account ...
    (microsoft.public.windows.server.active_directory)
  • Re: Does Ruby need a "line separator" class?
    ... to the filesystem for newlines, which as you describe above causes problems ... generates files with newlines...we normalize those newlines to \n and write ... if you pass a Unix text file to a line-oriented script running on Windows the script will work as long as it only reads. ... That's because LFs not following a CR are left untouched by the I/O layer, and by a happy coincidence LFs is what readline expects. ...
    (comp.lang.ruby)
  • Re: Rename Administrator Account to %computername%
    ... How can I get the admin account to effectively change and be ... You could do it in a computer startup script (with a GPO) that runs ... Script that renames the builtin administrator ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Local Printer Mapping Names
    ... Write a program or script that renames the autocreated printers during logon. ... You will need to impersonate a different user so that your program has enough rights to rename the printer, for example, create a special user that is a member of Power Users. ... If you want you can use a utility to run your script as a different account so you don't need to do the impersonation in your code. ...
    (microsoft.public.windows.terminal_services)
  • Re: cant get unlink to work on windows
    ... Sorry for not posting a complete script. ... are no newlines within the pathnames. ... print "$remfn, $cnt, $!"; ... Het volumenummer is 20A6-6074 ...
    (comp.lang.perl.misc)

Loading