Hi all,
Based on the following considerations, my solution for this problem is a
bit different from Ed's one above :
- "awk" is far more powerful than "find" for regexp filtering
- it's far simpler to list the authorized characters than to parse through
all filenames searching for the forbidden ones
I chose not to create "list" file and instead to pipe "find" output
directly in "awk". I also considered that only files had to be renamed,
not directories, so I applied modifications only to the last field of each
line :
find . -type f | nawk 'BEGIN {FS = "/"; OFS = "/"; authorized =
"[^a-zA-Z0-9._-]"}; $NF ~ authorized {wrong = $0; gsub(authorized, "",
$NF); printf("/usr/bin/mv \"%s\" \"%s\"\n", wrong, $0)}'
I've listed the usual basic characters used for UNIX filenames, but you
can just update the list of authorized characters (between the brackets in
"authorized" variable declaration) to your convenience and "awk" will do
the rest.
NB 1: When updating the list, pay attention to keep "^" as first character
and "-" as last, because in other positions, they would have different
meanings in the regexp.
NB 2: If modifications also concern directories names, remove declarations
of "FS" and "OFS", include "/" inside the brackets of "authorized"
characters and replace all occurences of "$NF" by "$0".
NB 3: If your "/usr/xpg4/bin/awk" is up-to-date in POSIX compliancy, you
should be able to rewrite "authorized" variable declaration like this :
authorized = "[^[:print:]._-]" ([:print:] meaning all alphanumeric
characters)
Cheers
Eric
--
PM :
http://www.webuse.net/pm.php?u=2832
Posted using
www.webuse.net