Resolved rename multiple files?

Discussion in 'Mac Basics and Help' started by Kaspin, Dec 30, 2015.

  1. Kaspin macrumors member

    Kaspin

    Joined:
    Jan 15, 2015
    #1
    I have lots of files named with the format of "Sometext_MMYYYY.pdf" (MM=month YYYY=Year) and I want them all as "Sometext_YYYYMM.pdf" so they're sorted chronologically. Is there anyway to automate this?
     
  2. Kaspin thread starter macrumors member

    Kaspin

    Joined:
    Jan 15, 2015
    #3
    I ended up using numbers to create a mv command list to paste into terminal using the MID string function. Screen Shot 2015-12-31 at 11.06.30 AM.png

    I was hoping to find a way to do it just in terminal, but I was only able to find syntax for replacing specific strings in file names, nothing similar to MID string function in numbers.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    The bash syntax for "substring" is:
    Code:
    ${parameter:offset:length}
    
    Refer to the bash man page, and find Substring Expansion on the page.
    https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/bash.1.html


    If I were doing this, I might have looked up the bash syntax, made a test that echoed the cmds, and done it that way. More likely, I would have made a small 'awk' program to do what you did: read inputs, transform into a series of 'mv' commands, then run the resulting cmds (i.e. piped to bash). This is mainly because I know awk.

    There are many other ways of doing the same thing, and Numbers is as good a way as any. The key insight is to see it as a problem of converting a series of names into a series of commands, then running those separately. Nice solution using Numbers.
     

Share This Page