Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Bash Item Selection Question

Bash Item Selection Question
Thread Tools
Jeordy
Fresh-Faced Recruit
Join Date: Feb 2011
Status: Offline
Reply With Quote
Feb 17, 2011, 12:46 PM
 
Hello,
I am trying to make a bash script that will sequentially rename files. The script itself doesn't need to worry about making sure it's rename it right, I just need it to rename files starting at the top of the files listed in ls and go down one at a time. What I'm trying to do is make a batch rename script that will rename the files sequentially. I know this can be done in automater easily with the "Get Specified Finder Items" and "Rename Finder Items" counters but I'd like to be able to do it in terminal.

My hiccup is getting it to run the for loop on only one item at a time.

I can make one that does *.mkv mv Episode ##.mkv but then it renames all the files in the folder to that because they all match *mkv.

I want to set it up once and be able to run it so that it can be compatible with any file name (shows and anime, etc.. come in crazy naming formats).

So how would I go about making the script test only the first in the list, then second, then third, etc... and not testing on the entire folder?

Thanks!!
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Feb 26, 2011, 07:49 PM
 
You need to do something like this:

Code:
for i in $( ls ); do mv $i ... done
Note: The padding spaces inside the parenthesis are important.
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Feb 28, 2011, 03:32 PM
 
Rainy Day's suggestion is identical to mine. If you want to combine those command onto a single line so that you don't have to write an actual script and just run the loop as a shell command, you can do that too.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:19 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,