-2

I want rename bunch of filenames. The rename is based on the calculation of the filename. That means the actual filename + 3600 = new filename. Important is that the underscore in the pid files have to stay.

Thanks in advance!

My system is Debian Stretch.

Actual Filename:

134235.error
134235_.pid
134235.tiff


13893.error
13893_.pid
13893.tiff

1.error
1_.pid
1.tiff

Rename to:

137835.error
137835_.pid
137835.tiff


17493.error
17493_.pid
17493.tiff

3601.error
3601_.pid
3601.tiff
Goeks
  • 51
  • 7
  • 1
    Sorry, this is not the way StackOverflow works. Questions of the form "I want to do X, please give me tips and/or sample code" are considered off-topic. Please visit the [help] and read [ask], and especially read [Why is β€œCan someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236) – kvantour Sep 18 '19 at 09:21
  • Possible duplicate of https://stackoverflow.com/questions/52640820/how-to-rename-files-in-bash-to-increase-number-in-name – tripleee Sep 18 '19 at 09:23

2 Answers2

3
for fname in *; do
   echo mv -- "$fname" "${fname/*[[:digit:]]/$((${fname%%[^[:digit:]]*}+3600))}"
done

If everything looks ok, remove echo.

oguz ismail
  • 1
  • 16
  • 47
  • 69
0

With Perl's standalone rename command. Some distributions call it prename.

rename -n 's/(\d+)(.+)/${\($1+3600)}$2/' *

If everything looks fine, remove -n.

Cyrus
  • 84,225
  • 14
  • 89
  • 153