Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Simple 'date' to 001 scheme script

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 10-20-2015
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 29 April 2017, 11:25 AM EDT
Location: Aachen, Germany
Posts: 10,705
Thanks: 264
Thanked 3,285 Times in 3,026 Posts
Not sure as this seems to be for DOS - is the %d a format string that could be replaced by e.g. %04d (as opposed to %x which is a loop variable)?
Sponsored Links
    #9  
Old Unix and Linux 10-20-2015
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 30 April 2017, 4:43 AM EDT
Location: San Jose, CA, USA
Posts: 10,225
Thanks: 514
Thanked 3,550 Times in 3,023 Posts
With the shell in busybox you should be able to do something like:

Code:
cnt=1
for x in *.gif
do      base="${x%.gif}"
        echo mv "$x" "$(printf '%s_%04d.gif' "$base" $cnt)"
        cnt=$((cnt + 1))
done

If that shows you a set of mv commands that do what you need to do, remove the echo and run it again to actually rename the files.
The Following User Says Thank You to Don Cragun For This Useful Post:
pasc (10-20-2015)
Sponsored Links
    #10  
Old Unix and Linux 10-20-2015
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 20 October 2015, 7:24 AM EDT
Posts: 139
Thanks: 26
Thanked 1 Time in 1 Post
Thanks!

Busybox seems to be rather useful Linux.
    #11  
Old Unix and Linux 10-26-2015
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 28 April 2017, 12:18 PM EDT
Location: Saskatchewan
Posts: 22,099
Thanks: 1,075
Thanked 4,159 Times in 3,849 Posts
Quote:
Originally Posted by RudiC View Post
Not sure as this seems to be for DOS - is the %d a format string that could be replaced by e.g. %04d (as opposed to %x which is a loop variable)?
He could likely feed that to imagemagick next time to get files with leading zeroes from the get-go.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to do simple date (time) calculation in shell script? nbsparks Shell Programming and Scripting 7 09-16-2013 05:59 PM
Help making simple perl or bash script to create a simple matrix torchij Shell Programming and Scripting 16 04-26-2012 04:05 AM
How can get the value 001 using shell script nmadhuhb Shell Programming and Scripting 2 07-20-2009 06:36 AM
Simple date formatting? muay_tb Shell Programming and Scripting 4 05-01-2009 10:08 AM
a simple way of converting a date in seconds to normal date travian HP-UX 2 11-23-2006 11:25 AM



All times are GMT -4. The time now is 04:57 AM.