Re: rename files
From: William Park (opengeometry_at_yahoo.ca)
Date: 09/08/04
- Next message: Dana French: "Re: Why 'alias' cannot run by shell script?"
- Previous message: William Park: "Re: bash arrays quoting nightmare?"
- In reply to: d0x: "rename files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Dana French: "Re: Why 'alias' cannot run by shell script?"
- Previous message: William Park: "Re: bash arrays quoting nightmare?"
- In reply to: d0x: "rename files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
Loading