Kevin
Kevin

Reputation: 13226

Find & replace a character in filenames from terminal

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.

Upvotes: 3

Views: 1253

Answers (1)

mob
mob

Reputation: 118605

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).

Upvotes: 3

Related Questions