Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kaspin

macrumors regular
Original poster
Jan 15, 2015
103
46
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?
 
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.
 
I ended up using numbers to create a mv command list to paste into terminal using the MID string function.View attachment 608155

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.
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.