3

I am trying to use ren-regexp to replace a character in filenames like so:

./ren-regexp.pl "s/_/-/g" *.jpg

Which I think should replace _ with - in filenames that are jpgs, but what I get is:

./ren-regexp.pl: line 4: syntax error near unexpected token `newline'
./ren-regexp.pl: line 4: `<!DOCTYPE html>'

I also tried

perl ren-regexp.pl "s/_/-/g" *.jpg

Which resulted in lots of errors such as:

Bareword found where operator expected at ren-regexp.pl line 252, near "time class"
    (Do you need to predeclare time?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""js-relative-date" datetime"
    (Missing operator before datetime?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""2011-04-13T16:40:41-07:00" title"
    (Missing operator before title?)
Number found where operator expected at ren-regexp.pl line 252, near "April 13"
    (Do you need to predeclare April?)
Bareword found where operator expected at ren-regexp.pl line 262, near ""/msabramo/ren-regexp/tree/17026c762c41e2b88ed91bf78b63e54859b706e5" class"
    (Missing operator before class?)

I tried using the examples shown on the GitHub page as well as here:

Mass replace characters in filenames from terminal?

Where am I going wrong? Running just 'perl ren-regexp.pl' by itself also results in the above set of errors.

Community
  • 1
  • 1
Kevin
  • 13,153
  • 11
  • 60
  • 87
  • 2
    are you sure you have a good download? sounds like your program is bad. What does “ren-regexp.pl” look like around line 250-260? – BRPocock Dec 27 '11 at 18:15
  • 1
    That script, by the looks of it, is quite... poorly written. Does not even use strict and warnings, and looks to be quite old. – TLP Dec 27 '11 at 19:42
  • Hundreds of lines of poor code to do `perl -MFile::Copy=move -Mautodie -we 'for (@ARGV { my $new = $_; $new =~ s/_/-/g; move $_, $new; }' *.jpg`? – TLP Dec 27 '11 at 20:02
  • It is from a few years ago but the only thing that kept popping up when looking for answers. – Kevin Dec 27 '11 at 20:19
  • It seems to be written 12 years ago, and updated last 2005. – TLP Dec 27 '11 at 20:27

1 Answers1

3

It looks like you downloaded the script from

https://github.com/msabramo/ren-regexp/blob/master/ren-regexp.pl

instead of

https://raw.github.com/msabramo/ren-regexp/master/ren-regexp.pl

The former link will actually give you an HTML document that is unsuitable for passing into perl.

Or you could view the first link in a browser, and then copy and paste the Perl code to a file (and strip the line numbers).

mob
  • 117,087
  • 18
  • 149
  • 283