Hi, y'all. Running Linux Mint and I have the puzzle presented above.

From what I gather, I'm using rename (1p) which makes mention of Perl and in the man page it says it will also run as file-rename. I'm not sure if this is the right rename utility for the common argument

s/old_pattern/new_pattern/

but any time I try to run anything (including -n), I just get an angle bracket > and have to ctrl-c out.

I'd also need some details on how the wildcards work, which seems to be lacking in the documentation.

Edit: Instructions unclear. I have a bunch of episodes that are very wordy. I'm moving them onto DVD and truncated on my player the directory will look like:

Star Trek The Next Gene....
Star Trek The Next Gene....
Star Trek The Next Gene....
Star Trek The Next Gene....
Star Trek The Next Gene....

so I want to take (sample episode)

Star Trek The Next Generation Season 1 Episode 1 - Encounter at Far Point

and

  • Replace 'Star Trek The Next Generation Season ' with 'S0'

  • Replace 'Episode ' with 'E0' or 'E' depending on digits

  • Keep episode title as is.

So it looks like

S01E01 - Encounter at Farpoint.mkv

you are viewing a single comment's thread
view the rest of the comments
[–] 5 points 5 months ago (2 children)

I think you want something like this:

$ ls
'Star Trek Next Generation Season 01 Episode 22 - Bob.mkv'
'Star Trek Next Generation Season 1 Episode 1 - Encounter at Farpoint.mkv'
$ file-rename 's/.*Season (\d+) Episode (\d+)/sprintf("S%02dE%02d", $1, $2)/ie' *.mkv
$ ls
'S01E01 - Encounter at Farpoint.mkv'  'S01E22 - Bob.mkv'

If you are getting an angle bracket, it's probably because you didn't add *.mkv at the end.

  • source
  • hideshow 2 child comments
  • [–] [S] 1 point 5 months ago* (last edited 5 months ago) (1 child)

    Thanks! I'll dig into this tonight. The man page could use a bit of work, too, if you're feeling generous. A lot is assumed to be known.

    Edit: Your entry is winning “shortest code” so fa r...

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 5 months ago*

    It's so short because it's special-purpose rather than general purpose. Perl is a programming language that can do lots and lots of different things. file-rename does one thing, and one thing very well: it renames files using regex

  • source
  • parent