[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Simple renaming problem....help...ASAP !!!!

Hi !

I have a folder containg files in order ..i.e. 1.pl, 2.pl , 3.pl , 4.pl , 5.pl and so on...

the folder also contains other files...now what i want is that when i delete 3.pl and 1.pl , i should be able to run a script which renames 2.pl as 1.pl 4.pl as 2.pl and 5.pl as 3.pl ... this is just an example.. i should be able to delete any files and then run the script inorder to make them 1,2,3,4,5 and so on..... i hope u understand what it means...

please help asap...
thanks in advance
0
anant99
Asked:
anant99
1 Solution
 
ahoffmannCommented:
ls [0-9]*.pl|sed 's/\.pl//'|sort|awk '{print "mv "$0".pl "++x".pl"}'|sh
0
 
glewisCommented:
Obviously, you didn't like the Unix/Linux command-line (shell) option.  What language would you like it in?  Perl?  Ruby?
-- Glenn
0
 
ozoCommented:
perl -e 'rename$_,++$x.".pl"for sort{$a<=>$b}<[0-9]*.pl>'
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now