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

  • MagnificentSteiner@lemmy.zip
    link
    fedilink
    English
    arrow-up
    8
    ·
    edit-2
    10 days ago

    Tested this with perl-rename and it seems to work fine:

    perl-rename -n 's/.* (\d{1,2}).* (\d{1,2})/sprintf "S%02dE%02d",$1,$2/e' *

    -n does a test-run and shows you the results, remove it to do the actual rename

    ‘s/ text to find / text to replace it with / modifier’ is the format used

    . represents any single character

    ‘*’ matches the previous character 1 or more times

    '.* ’ matches any series of characters before a space

    () encloses something you want to keep

    \ is the escape character

    d represents any number

    {1,2} means the number will be 1 or 2 digits

    In the sprintf, %02d is to format each number with 2 digits.

    $1 and $2 pass the first and second values enclosed in parentheses from the first argument into the 2 d’s in the “S%02dE%02d” of the second argument.

    This link has a better explanation of the /e modifier than I could give you xD

    https://www.geeksforgeeks.org/perl/perl-e-modifier-in-regular-expression/ ___

    • schipelblorp@sh.itjust.worksOP
      link
      fedilink
      arrow-up
      6
      ·
      11 days ago

      Cool! Thanks!

      Is this standard PERL stuff? How I learn what all these things mean? One day I hope to write my own arguments.

      • MagnificentSteiner@lemmy.zip
        link
        fedilink
        English
        arrow-up
        4
        ·
        edit-2
        11 days ago

        No idea lol

        I just wanted a rename utility and Arch didn’t have the GUI one I used on Mint so I gradually pieced some of this stuff together. If there’s one source online that lays it all out I haven’t found it yet!

        If you’d like me to explain the one here I’ll do my best ;)

        Edit: nvm, I edited the original comment to explain everything

      • forestbeasts@pawb.social
        link
        fedilink
        arrow-up
        4
        ·
        edit-2
        9 days ago

        Perl has its own man pages, like commands do, but specifically for Perl stuff!

        There’s also a “perldoc” command that works a lot like man, that documents the functions and things.

        For this, check out perldoc -f s (the s “function”) and man perlretut (regular expressions). MagnificentSteiner here is using /e on the end of the regex to write Perl code in the replacement instead of a string (that’s mentioned in the perlre man page), and then using the sprintf function to do some formatting, which, perldoc -f sprintf.

        For a general intro to Perl, man perlintro!

        … Oh, uh, you may need to install the perl-doc package (or equivalent) to have any of this documentation.

        – Frost