![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| file name transformation | vrms | Shell Programming and Scripting | 16 | 05-27-2008 08:49 AM |
| Color Transformation Language 1.4.1 (Default branch) | iBot | Software Releases - RSS News | 0 | 03-18-2008 08:10 AM |
| Event Transformation Services | iBot | Complex Event Processing RSS News | 0 | 08-24-2007 03:30 PM |
| Apply transformation logic in 2 different files | HAA | Shell Programming and Scripting | 1 | 07-10-2007 04:33 AM |
| how to find capital letter names in a file without finding words at start of sentence | kev269 | Shell Programming and Scripting | 1 | 04-10-2006 09:35 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
Hye everybody i would like to know if exist a internet site where i can founs some interesting shell script very usefull I need to transform hundreds names of files escribed in CAPITAL letter in minuscule letter do oyu know a mean o do that that thanks to a script or a shell command |
|
|||||
|
go to www.ugu.com sign up for the tip of the day.
Dear Dark,
Here is a very good script. That should do the trick. You will have to modify it of course. It is not mine. But here it is. Code:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UNIX GURU UNIVERSE & UNIX911.com
UNIX HOT TIP
Unix Tip 1661 - July 19, 2001
http://www.ugu.com/sui/ugu/show?tip.today
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rename files script
If you want to rename files
in a directory then you can
use the following perl
script....
#!/usr/bin/perl
# rename: renames files according to the expr given on the command line.
# The expr will usually be a 's' or 'y' command, but can be any valid
# perl command if it makes sense. Takes a list of files to work on or
# defaults to '*' in the current directory.
# e.g.
# rename 's/\.flip$/.flop/' # rename *.flip to *.flop
# rename s/flip/flop/ # rename *flip* to *flop*
# rename 's/^s\.(.*)/$1.X/' # switch sccs filenames around
# rename 's/$/.orig/' */*.[ch] # add .orig to your source files in
*/
# rename 'y/A-Z/a-z/' # lowercase all filenames in .
# rename 'y/A-Z/a-z/ if -B' # same, but just binaries!
# rename chop *~ # restore all ~ backup files
use Getopt::Std;
my ($subst, $name);
if (!&getopts("nfq") || $#ARGV == -1) {
die "Usage: rename [-fnq] <perl expression> [file file...]
-f : Force the new filename even if it exists already
-n : Just print what would happen, but don't do the command
-q : Don't print the files as they are renamed
e.g. : rename 's/\.c/.c.old/' *
rename -q 'y/A-Z/a-z/' *\n";
}
$subst = shift; # Get perl command to work on
@ARGV = <*> if $#ARGV < 0; # Default to complete directory
foreach $name (@ARGV) {
$_ = $name;
eval "$subst;";
die $@ if $@;
next if -e $_ && !$opt_f; # Skip if the file exists if asked to.
mext if $_ eq $name;
if ($opt_n) {
print "mv $name $_\n";
next;
}
print "mv $name $_\n" if !$opt_q;
rename($name,$_) or warn "Can't rename $name to $_, $!\n";
}
Put the script called rename in /usr/local/bin. Make sure
/usr/local/bin is in your $PATH for convenience.
This tip generously supported by: dave.ruddle@siemens.co.uk
Last edited by oombera; 02-16-2004 at 11:36 AM.. |
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|