SHARE
TWEET

Untitled

a guest Jun 26th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. xx 1 abc.txt
  2. xx 2 def.txt
  3. xx 3 ghi.txt
  4. xx 3.5 jkl.txt
  5. xx 4a mno.txt
  6. xx 4b pqr.txt
  7. ...
  8. xx 100 end.txt
  9.      
  10. xx 001 abc.txt
  11. xx 002 def.txt
  12. xx 003 ghi.txt
  13. xx 003.5 jkl.txt
  14. xx 004a mno.txt
  15. xx 004b pqr.txt
  16. ...
  17. xx 100 end.txt
  18.      
  19. #!/usr/bin/perl
  20. opendir(DIR, ".");
  21. @files = sort(grep(/txt$/i, readdir(DIR)));
  22. closedir(DIR);
  23.  
  24. $len=0;
  25. foreach $file (@files) {
  26.     print $file."n";
  27.     if ($file=~/xx (d+)(.*.txt)$/i) {
  28.         $len=(length($1)>$len)?length($1):$len;
  29.     }
  30. }
  31. foreach $file (@files) {
  32.     if ($file=~/xx (d+)(.*.txt)$/i) {
  33.         $newfile=sprintf("%0${len}d%s", $1, $2);
  34.         rename("$file", "$newfile");
  35.     }
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top