Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Clean filenames with /usr/bin/rename

by thinker (Parson)
on Jun 17, 2003 at 07:59 UTC ( [id://266404]=note: print w/replies, xml ) Need Help??


in reply to Clean filenames with /usr/bin/rename

Hi bsb,

The following should rename all the files in the current directory in the fashion you wish.
perl -e 'for (<*>){ my $f= $_; tr/, -/_/s; rename $f, $_}'

I hope this helps
thinker

Update Whoops, forgot the lower case. Quick fix.
perl -e 'for (<*>){ my $f= $_; tr/, -/_/s; tr/A-Z/a-z/; rename $f, $_} +'

Replies are listed 'Best First'.
Re: Re: Clean filenames with /usr/bin/rename
by bsb (Priest) on Jun 17, 2003 at 23:18 UTC
    Thanks but the program already exists and it's in Perl:
    $ head -n 4 `which rename` #!/usr/bin/perl -w # # This script was developed by Robin Barker (Robin.Barker@npl.co.uk), # from Larry Wall's original script eg/rename from the perl source.
    I just need a new improved expression that catches all stupid file names and converts them to something sensible. The original post does it ok, I'd hoped someone had a thoroughly tested expression ready to post.

      Let me try it again. See sub sanitize for the matching pattern in various s///, in the referenced program, that i consider fit the mold of unholy names on unix. You could then round up all the matching regexen to create one regex for rename.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://266404]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found