-3

I have a folder of files named ts200.jpg, ts201.jpg, and so on. I need a program or command that will see the number, and minus 199 from the number, so ts200.jpg would become ts1.jpg, and so on.

I installed PERL rename, but I cannot comprehend the docs.

Any answers appreciated.

  • Please edit your question (no comment): What have you searched for, and what did you find? What have you tried, and how did it fail? – Cyrus May 07 '23 at 09:31

1 Answers1

1

I'd just use a perl one-liner directly, not its rename utility:

$ ls *.jpg
ts200.jpg ts201.jpg
$ perl -e 'rename $_, $_ =~ s/\d+/$&-199/er for @ARGV' *.jpg
$ ls *.jpg
ts1.jpg ts2.jpg
Shawn
  • 47,241
  • 3
  • 26
  • 60
  • Just to double check, if I had more files up to like, ts600.jpg, would it still work? – WiiCoder4444 May 07 '23 at 09:42
  • @WiiCoder4444 Yeah. – Shawn May 07 '23 at 10:04
  • 1
    Re "*if I had more files up to like, ts600.jpg, would it still work?*", 1) `*.jpg` might produce a command line that's too long if you have hundreds of files. This could be resolved using `find ... -exec perl -e'...' {} +`. 2) **It could result in data loss.** Imagine if ts600 gets renamed to ts401 before ts401 gets renamed? This can be fixed by moving them to a new directory by using `rename $_, "new/" . s/\d+/$&-199/er`. – ikegami May 07 '23 at 20:56
  • Thanks! Next time i do a timelapse ill use that command – WiiCoder4444 Jul 15 '23 at 09:25