How do I add zero padding to filenames that already have numbers in them? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
7
down vote

favorite
3













This question already has an answer here:



  • Renaming hundreds of files at once for proper sorting

    6 answers



I used Sound Juicer to rip a CD of audio for a language learning book so that I could listen to them on my Android. However, Sound Juicer seems to only have the option of numbering files without leading zeros. Like this:



track_1.mp3
track_10.mp3
track_11.mp3


This leads to some confused ordering on my music player. So, I want to add some zeros to the name, so that they're ordered properly, like this:



track_01.mp3
track_02.mp3
track_03.mp3


How do I accomplish this? I tried using GPRename, but while it has the ability to add numbers, it doesn't seem to have any options for adding leading zeros.



Is there a better program or something I can do at the command line?










share|improve this question















marked as duplicate by Oli♦ Jul 28 '14 at 14:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • My answer on the duplicate should answer this pretty completely in a single command.
    – Oli♦
    Jul 28 '14 at 14:13






  • 1




    @Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
    – Jacob Vlijm
    Jul 28 '14 at 15:58










  • @Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
    – Questioner
    Jul 28 '14 at 23:51






  • 1




    also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
    – Jacob Vlijm
    Jul 29 '14 at 18:35






  • 1




    @muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
    – Oli♦
    Jul 30 '14 at 15:31














up vote
7
down vote

favorite
3













This question already has an answer here:



  • Renaming hundreds of files at once for proper sorting

    6 answers



I used Sound Juicer to rip a CD of audio for a language learning book so that I could listen to them on my Android. However, Sound Juicer seems to only have the option of numbering files without leading zeros. Like this:



track_1.mp3
track_10.mp3
track_11.mp3


This leads to some confused ordering on my music player. So, I want to add some zeros to the name, so that they're ordered properly, like this:



track_01.mp3
track_02.mp3
track_03.mp3


How do I accomplish this? I tried using GPRename, but while it has the ability to add numbers, it doesn't seem to have any options for adding leading zeros.



Is there a better program or something I can do at the command line?










share|improve this question















marked as duplicate by Oli♦ Jul 28 '14 at 14:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • My answer on the duplicate should answer this pretty completely in a single command.
    – Oli♦
    Jul 28 '14 at 14:13






  • 1




    @Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
    – Jacob Vlijm
    Jul 28 '14 at 15:58










  • @Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
    – Questioner
    Jul 28 '14 at 23:51






  • 1




    also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
    – Jacob Vlijm
    Jul 29 '14 at 18:35






  • 1




    @muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
    – Oli♦
    Jul 30 '14 at 15:31












up vote
7
down vote

favorite
3









up vote
7
down vote

favorite
3






3






This question already has an answer here:



  • Renaming hundreds of files at once for proper sorting

    6 answers



I used Sound Juicer to rip a CD of audio for a language learning book so that I could listen to them on my Android. However, Sound Juicer seems to only have the option of numbering files without leading zeros. Like this:



track_1.mp3
track_10.mp3
track_11.mp3


This leads to some confused ordering on my music player. So, I want to add some zeros to the name, so that they're ordered properly, like this:



track_01.mp3
track_02.mp3
track_03.mp3


How do I accomplish this? I tried using GPRename, but while it has the ability to add numbers, it doesn't seem to have any options for adding leading zeros.



Is there a better program or something I can do at the command line?










share|improve this question
















This question already has an answer here:



  • Renaming hundreds of files at once for proper sorting

    6 answers



I used Sound Juicer to rip a CD of audio for a language learning book so that I could listen to them on my Android. However, Sound Juicer seems to only have the option of numbering files without leading zeros. Like this:



track_1.mp3
track_10.mp3
track_11.mp3


This leads to some confused ordering on my music player. So, I want to add some zeros to the name, so that they're ordered properly, like this:



track_01.mp3
track_02.mp3
track_03.mp3


How do I accomplish this? I tried using GPRename, but while it has the ability to add numbers, it doesn't seem to have any options for adding leading zeros.



Is there a better program or something I can do at the command line?





This question already has an answer here:



  • Renaming hundreds of files at once for proper sorting

    6 answers







rename batch-rename






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 28 '14 at 14:02









guntbert

8,750123067




8,750123067










asked Jul 28 '14 at 4:12









Questioner

1,4482480146




1,4482480146




marked as duplicate by Oli♦ Jul 28 '14 at 14:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Oli♦ Jul 28 '14 at 14:11


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • My answer on the duplicate should answer this pretty completely in a single command.
    – Oli♦
    Jul 28 '14 at 14:13






  • 1




    @Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
    – Jacob Vlijm
    Jul 28 '14 at 15:58










  • @Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
    – Questioner
    Jul 28 '14 at 23:51






  • 1




    also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
    – Jacob Vlijm
    Jul 29 '14 at 18:35






  • 1




    @muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
    – Oli♦
    Jul 30 '14 at 15:31
















  • My answer on the duplicate should answer this pretty completely in a single command.
    – Oli♦
    Jul 28 '14 at 14:13






  • 1




    @Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
    – Jacob Vlijm
    Jul 28 '14 at 15:58










  • @Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
    – Questioner
    Jul 28 '14 at 23:51






  • 1




    also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
    – Jacob Vlijm
    Jul 29 '14 at 18:35






  • 1




    @muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
    – Oli♦
    Jul 30 '14 at 15:31















My answer on the duplicate should answer this pretty completely in a single command.
– Oli♦
Jul 28 '14 at 14:13




My answer on the duplicate should answer this pretty completely in a single command.
– Oli♦
Jul 28 '14 at 14:13




1




1




@Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
– Jacob Vlijm
Jul 28 '14 at 15:58




@Oli, although your answer works here too, the question actually is different, and other answers there do not necessarily work here, because of the preceding track_ string. Mine needed editing anyway to make it work on this question.
– Jacob Vlijm
Jul 28 '14 at 15:58












@Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
– Questioner
Jul 28 '14 at 23:51




@Oli, Jacob is correct. I had looked at similar solutions to the question you've linked to, but because of the particular naming scheme I was dealing with, it wasn't obvious that any file numbering solution would work. Marking this as duplicate is presuming a level of knowledge that precludes the purpose of asking questions.
– Questioner
Jul 28 '14 at 23:51




1




1




also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
– Jacob Vlijm
Jul 29 '14 at 18:35




also @muru, the fact that you can produce an answer that works on more than one question does not make the questions equal. See my reaction on meta meta.askubuntu.com/questions/11622/are-these-duplicates
– Jacob Vlijm
Jul 29 '14 at 18:35




1




1




@muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
– Oli♦
Jul 30 '14 at 15:31




@muru Off-topic to the duplication issue, that line would munch the extension. There is certainly a way similar to that which would work though.
– Oli♦
Jul 30 '14 at 15:31










5 Answers
5






active

oldest

votes

















up vote
8
down vote



accepted










I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



You can execute the below command:



for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.




To break it down, it looks like this:



for n in $(seq 9)
do
mv track_$n.mp3 track_0$n.mp3
done



  • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,


  • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.





share|improve this answer



























    up vote
    4
    down vote













    The script below wil rename files is given directory. It calculates the number of leading zeros needed, no matter the number of files (if >100, more zeros are needed), and renames the files automatically.



    To use it



    copy the script below into an empty file, in the headsection, set the sourcedirectory, the prefix ("track-" in this case) and the file extension of the files you want to rename. Save it as rename.py and run it by the command:



    python3 /path/to/script.py


    The script:



    #!/usr/bin/env python3

    import shutil
    import os

    sourcedir = "/path/to/sourcedir"
    prefix = "track_"
    extension = "mp3"

    files = [(f, f[f.rfind("."):], f[:f.rfind(".")].replace(prefix, "")) for f in os.listdir(sourcedir) if f.endswith(extension)]
    maxlen = len(max([f[2] for f in files], key = len))

    for item in files:
    zeros = maxlen - len(item[2])
    shutil.move(sourcedir+"/"+item[0], sourcedir+"/"+prefix+str(zeros*"0"+item[2])+item[1])





    share|improve this answer





























      up vote
      1
      down vote













      Of course there are many ways of doing it. You can, for instance:



      • Separate the parts

      • pad the part that has the number

      • concatenate the individual part back to the new name

      Put this into a loop:



      #!/bin/bash

      item="track_1.mp3"

      part1=`echo $item | awk -F_ 'print $1'`
      part2=`echo $item | awk -F_ 'print $2'`
      part2a=`echo $part2 | awk -F. 'print $1'`
      part2b=`echo $part2 | awk -F. 'print $2'`
      number=`printf "%02d" $part2a`
      seperator="_"
      newname="$part1$seperator$number.$part2b"
      echo $newname


      The loop:



      #!/bin/bash

      for item in track_1.mp3 track_10.mp3 track_11.mp3
      do
      part1=`echo $item | awk -F_ 'print $1'`
      part2=`echo $item | awk -F_ 'print $2'`
      part2a=`echo $part2 | awk -F. 'print $1'`
      part2b=`echo $part2 | awk -F. 'print $2'`
      number=`printf "%02d" $part2a`
      seperator="_"
      newname="$part1$seperator$number.$part2b"
      echo "Renaming $item -> $newname"
      mv $item $newname
      done
      enter code here





      share|improve this answer





























        up vote
        1
        down vote













        GPRename will automatically insert a zero if you are renaming 10 or more files (two if you are renaming 100 or more, etc.) when using the numerical function. Just make sure Zero auto-fill is turned on in the Options menu.






        share|improve this answer




















        • This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
          – Questioner
          Jul 28 '14 at 9:10

















        up vote
        1
        down vote













        Make a script that will work like a command.



        Make this file on the directory where you track file exist.




        • Do like this



          touch change
          chmod +x change
          vim change



        • In it write



          #!/bin/bash
          n=0
          for m in 00 .. 99
          do
          mv track_$n.mp3 track_$m
          n=`expr $n + 1``
          done






        share|improve this answer






















        • This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
          – Boris the Spider
          Jul 28 '14 at 8:24










        • you can check the updated answer.
          – Dishank Jindal
          Jul 28 '14 at 8:43










        • Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
          – Boris the Spider
          Jul 28 '14 at 8:49











        • the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
          – Dishank Jindal
          Jul 28 '14 at 8:52

















        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        8
        down vote



        accepted










        I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



        You can execute the below command:



        for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


        This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.




        To break it down, it looks like this:



        for n in $(seq 9)
        do
        mv track_$n.mp3 track_0$n.mp3
        done



        • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,


        • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.





        share|improve this answer
























          up vote
          8
          down vote



          accepted










          I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



          You can execute the below command:



          for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


          This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.




          To break it down, it looks like this:



          for n in $(seq 9)
          do
          mv track_$n.mp3 track_0$n.mp3
          done



          • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,


          • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.





          share|improve this answer






















            up vote
            8
            down vote



            accepted







            up vote
            8
            down vote



            accepted






            I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



            You can execute the below command:



            for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


            This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.




            To break it down, it looks like this:



            for n in $(seq 9)
            do
            mv track_$n.mp3 track_0$n.mp3
            done



            • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,


            • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.





            share|improve this answer












            I'm assuming that you just need to rename the files 1-9, since those are the ones that need padding. There are multiple ways of doing this.



            You can execute the below command:



            for n in $(seq 9); do mv track_$n.mp3 track_0$n.mp3; done;


            This will rename tracks track_1.mp3 - track_9.mp3 to track_01.mp3 - track_09.mp3.




            To break it down, it looks like this:



            for n in $(seq 9)
            do
            mv track_$n.mp3 track_0$n.mp3
            done



            • for n in $(seq 9): for every number in the output of the command seq 9, which is a command that just lists numbers 1 to 9, do,


            • mv track_$n.mp3 track_0$n.mp3: this is the actual command that renames the files. It substitutes the value of n iterating through all numbers. So it does mv track_1.mp3 track_01.mp3, mv track_2.mp3 track_02.mp3, until that last number which is 9.






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 28 '14 at 5:04









            Alaa Ali

            21.2k96793




            21.2k96793






















                up vote
                4
                down vote













                The script below wil rename files is given directory. It calculates the number of leading zeros needed, no matter the number of files (if >100, more zeros are needed), and renames the files automatically.



                To use it



                copy the script below into an empty file, in the headsection, set the sourcedirectory, the prefix ("track-" in this case) and the file extension of the files you want to rename. Save it as rename.py and run it by the command:



                python3 /path/to/script.py


                The script:



                #!/usr/bin/env python3

                import shutil
                import os

                sourcedir = "/path/to/sourcedir"
                prefix = "track_"
                extension = "mp3"

                files = [(f, f[f.rfind("."):], f[:f.rfind(".")].replace(prefix, "")) for f in os.listdir(sourcedir) if f.endswith(extension)]
                maxlen = len(max([f[2] for f in files], key = len))

                for item in files:
                zeros = maxlen - len(item[2])
                shutil.move(sourcedir+"/"+item[0], sourcedir+"/"+prefix+str(zeros*"0"+item[2])+item[1])





                share|improve this answer


























                  up vote
                  4
                  down vote













                  The script below wil rename files is given directory. It calculates the number of leading zeros needed, no matter the number of files (if >100, more zeros are needed), and renames the files automatically.



                  To use it



                  copy the script below into an empty file, in the headsection, set the sourcedirectory, the prefix ("track-" in this case) and the file extension of the files you want to rename. Save it as rename.py and run it by the command:



                  python3 /path/to/script.py


                  The script:



                  #!/usr/bin/env python3

                  import shutil
                  import os

                  sourcedir = "/path/to/sourcedir"
                  prefix = "track_"
                  extension = "mp3"

                  files = [(f, f[f.rfind("."):], f[:f.rfind(".")].replace(prefix, "")) for f in os.listdir(sourcedir) if f.endswith(extension)]
                  maxlen = len(max([f[2] for f in files], key = len))

                  for item in files:
                  zeros = maxlen - len(item[2])
                  shutil.move(sourcedir+"/"+item[0], sourcedir+"/"+prefix+str(zeros*"0"+item[2])+item[1])





                  share|improve this answer
























                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote









                    The script below wil rename files is given directory. It calculates the number of leading zeros needed, no matter the number of files (if >100, more zeros are needed), and renames the files automatically.



                    To use it



                    copy the script below into an empty file, in the headsection, set the sourcedirectory, the prefix ("track-" in this case) and the file extension of the files you want to rename. Save it as rename.py and run it by the command:



                    python3 /path/to/script.py


                    The script:



                    #!/usr/bin/env python3

                    import shutil
                    import os

                    sourcedir = "/path/to/sourcedir"
                    prefix = "track_"
                    extension = "mp3"

                    files = [(f, f[f.rfind("."):], f[:f.rfind(".")].replace(prefix, "")) for f in os.listdir(sourcedir) if f.endswith(extension)]
                    maxlen = len(max([f[2] for f in files], key = len))

                    for item in files:
                    zeros = maxlen - len(item[2])
                    shutil.move(sourcedir+"/"+item[0], sourcedir+"/"+prefix+str(zeros*"0"+item[2])+item[1])





                    share|improve this answer














                    The script below wil rename files is given directory. It calculates the number of leading zeros needed, no matter the number of files (if >100, more zeros are needed), and renames the files automatically.



                    To use it



                    copy the script below into an empty file, in the headsection, set the sourcedirectory, the prefix ("track-" in this case) and the file extension of the files you want to rename. Save it as rename.py and run it by the command:



                    python3 /path/to/script.py


                    The script:



                    #!/usr/bin/env python3

                    import shutil
                    import os

                    sourcedir = "/path/to/sourcedir"
                    prefix = "track_"
                    extension = "mp3"

                    files = [(f, f[f.rfind("."):], f[:f.rfind(".")].replace(prefix, "")) for f in os.listdir(sourcedir) if f.endswith(extension)]
                    maxlen = len(max([f[2] for f in files], key = len))

                    for item in files:
                    zeros = maxlen - len(item[2])
                    shutil.move(sourcedir+"/"+item[0], sourcedir+"/"+prefix+str(zeros*"0"+item[2])+item[1])






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 18 at 8:57









                    muru

                    130k19273463




                    130k19273463










                    answered Jul 28 '14 at 9:29









                    Jacob Vlijm

                    61.8k9120214




                    61.8k9120214




















                        up vote
                        1
                        down vote













                        Of course there are many ways of doing it. You can, for instance:



                        • Separate the parts

                        • pad the part that has the number

                        • concatenate the individual part back to the new name

                        Put this into a loop:



                        #!/bin/bash

                        item="track_1.mp3"

                        part1=`echo $item | awk -F_ 'print $1'`
                        part2=`echo $item | awk -F_ 'print $2'`
                        part2a=`echo $part2 | awk -F. 'print $1'`
                        part2b=`echo $part2 | awk -F. 'print $2'`
                        number=`printf "%02d" $part2a`
                        seperator="_"
                        newname="$part1$seperator$number.$part2b"
                        echo $newname


                        The loop:



                        #!/bin/bash

                        for item in track_1.mp3 track_10.mp3 track_11.mp3
                        do
                        part1=`echo $item | awk -F_ 'print $1'`
                        part2=`echo $item | awk -F_ 'print $2'`
                        part2a=`echo $part2 | awk -F. 'print $1'`
                        part2b=`echo $part2 | awk -F. 'print $2'`
                        number=`printf "%02d" $part2a`
                        seperator="_"
                        newname="$part1$seperator$number.$part2b"
                        echo "Renaming $item -> $newname"
                        mv $item $newname
                        done
                        enter code here





                        share|improve this answer


























                          up vote
                          1
                          down vote













                          Of course there are many ways of doing it. You can, for instance:



                          • Separate the parts

                          • pad the part that has the number

                          • concatenate the individual part back to the new name

                          Put this into a loop:



                          #!/bin/bash

                          item="track_1.mp3"

                          part1=`echo $item | awk -F_ 'print $1'`
                          part2=`echo $item | awk -F_ 'print $2'`
                          part2a=`echo $part2 | awk -F. 'print $1'`
                          part2b=`echo $part2 | awk -F. 'print $2'`
                          number=`printf "%02d" $part2a`
                          seperator="_"
                          newname="$part1$seperator$number.$part2b"
                          echo $newname


                          The loop:



                          #!/bin/bash

                          for item in track_1.mp3 track_10.mp3 track_11.mp3
                          do
                          part1=`echo $item | awk -F_ 'print $1'`
                          part2=`echo $item | awk -F_ 'print $2'`
                          part2a=`echo $part2 | awk -F. 'print $1'`
                          part2b=`echo $part2 | awk -F. 'print $2'`
                          number=`printf "%02d" $part2a`
                          seperator="_"
                          newname="$part1$seperator$number.$part2b"
                          echo "Renaming $item -> $newname"
                          mv $item $newname
                          done
                          enter code here





                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Of course there are many ways of doing it. You can, for instance:



                            • Separate the parts

                            • pad the part that has the number

                            • concatenate the individual part back to the new name

                            Put this into a loop:



                            #!/bin/bash

                            item="track_1.mp3"

                            part1=`echo $item | awk -F_ 'print $1'`
                            part2=`echo $item | awk -F_ 'print $2'`
                            part2a=`echo $part2 | awk -F. 'print $1'`
                            part2b=`echo $part2 | awk -F. 'print $2'`
                            number=`printf "%02d" $part2a`
                            seperator="_"
                            newname="$part1$seperator$number.$part2b"
                            echo $newname


                            The loop:



                            #!/bin/bash

                            for item in track_1.mp3 track_10.mp3 track_11.mp3
                            do
                            part1=`echo $item | awk -F_ 'print $1'`
                            part2=`echo $item | awk -F_ 'print $2'`
                            part2a=`echo $part2 | awk -F. 'print $1'`
                            part2b=`echo $part2 | awk -F. 'print $2'`
                            number=`printf "%02d" $part2a`
                            seperator="_"
                            newname="$part1$seperator$number.$part2b"
                            echo "Renaming $item -> $newname"
                            mv $item $newname
                            done
                            enter code here





                            share|improve this answer














                            Of course there are many ways of doing it. You can, for instance:



                            • Separate the parts

                            • pad the part that has the number

                            • concatenate the individual part back to the new name

                            Put this into a loop:



                            #!/bin/bash

                            item="track_1.mp3"

                            part1=`echo $item | awk -F_ 'print $1'`
                            part2=`echo $item | awk -F_ 'print $2'`
                            part2a=`echo $part2 | awk -F. 'print $1'`
                            part2b=`echo $part2 | awk -F. 'print $2'`
                            number=`printf "%02d" $part2a`
                            seperator="_"
                            newname="$part1$seperator$number.$part2b"
                            echo $newname


                            The loop:



                            #!/bin/bash

                            for item in track_1.mp3 track_10.mp3 track_11.mp3
                            do
                            part1=`echo $item | awk -F_ 'print $1'`
                            part2=`echo $item | awk -F_ 'print $2'`
                            part2a=`echo $part2 | awk -F. 'print $1'`
                            part2b=`echo $part2 | awk -F. 'print $2'`
                            number=`printf "%02d" $part2a`
                            seperator="_"
                            newname="$part1$seperator$number.$part2b"
                            echo "Renaming $item -> $newname"
                            mv $item $newname
                            done
                            enter code here






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jul 28 '14 at 6:05

























                            answered Jul 28 '14 at 4:53









                            L. D. James

                            17.5k43178




                            17.5k43178




















                                up vote
                                1
                                down vote













                                GPRename will automatically insert a zero if you are renaming 10 or more files (two if you are renaming 100 or more, etc.) when using the numerical function. Just make sure Zero auto-fill is turned on in the Options menu.






                                share|improve this answer




















                                • This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                  – Questioner
                                  Jul 28 '14 at 9:10














                                up vote
                                1
                                down vote













                                GPRename will automatically insert a zero if you are renaming 10 or more files (two if you are renaming 100 or more, etc.) when using the numerical function. Just make sure Zero auto-fill is turned on in the Options menu.






                                share|improve this answer




















                                • This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                  – Questioner
                                  Jul 28 '14 at 9:10












                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                GPRename will automatically insert a zero if you are renaming 10 or more files (two if you are renaming 100 or more, etc.) when using the numerical function. Just make sure Zero auto-fill is turned on in the Options menu.






                                share|improve this answer












                                GPRename will automatically insert a zero if you are renaming 10 or more files (two if you are renaming 100 or more, etc.) when using the numerical function. Just make sure Zero auto-fill is turned on in the Options menu.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 28 '14 at 6:34









                                Aibara

                                5,80463158




                                5,80463158











                                • This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                  – Questioner
                                  Jul 28 '14 at 9:10
















                                • This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                  – Questioner
                                  Jul 28 '14 at 9:10















                                This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                – Questioner
                                Jul 28 '14 at 9:10




                                This is useful to know. Although, GPRename, seems to not acknowledge existing numbers, so it seems to not fix this particular situation.
                                – Questioner
                                Jul 28 '14 at 9:10










                                up vote
                                1
                                down vote













                                Make a script that will work like a command.



                                Make this file on the directory where you track file exist.




                                • Do like this



                                  touch change
                                  chmod +x change
                                  vim change



                                • In it write



                                  #!/bin/bash
                                  n=0
                                  for m in 00 .. 99
                                  do
                                  mv track_$n.mp3 track_$m
                                  n=`expr $n + 1``
                                  done






                                share|improve this answer






















                                • This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:24










                                • you can check the updated answer.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:43










                                • Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:49











                                • the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:52














                                up vote
                                1
                                down vote













                                Make a script that will work like a command.



                                Make this file on the directory where you track file exist.




                                • Do like this



                                  touch change
                                  chmod +x change
                                  vim change



                                • In it write



                                  #!/bin/bash
                                  n=0
                                  for m in 00 .. 99
                                  do
                                  mv track_$n.mp3 track_$m
                                  n=`expr $n + 1``
                                  done






                                share|improve this answer






















                                • This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:24










                                • you can check the updated answer.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:43










                                • Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:49











                                • the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:52












                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote









                                Make a script that will work like a command.



                                Make this file on the directory where you track file exist.




                                • Do like this



                                  touch change
                                  chmod +x change
                                  vim change



                                • In it write



                                  #!/bin/bash
                                  n=0
                                  for m in 00 .. 99
                                  do
                                  mv track_$n.mp3 track_$m
                                  n=`expr $n + 1``
                                  done






                                share|improve this answer














                                Make a script that will work like a command.



                                Make this file on the directory where you track file exist.




                                • Do like this



                                  touch change
                                  chmod +x change
                                  vim change



                                • In it write



                                  #!/bin/bash
                                  n=0
                                  for m in 00 .. 99
                                  do
                                  mv track_$n.mp3 track_$m
                                  n=`expr $n + 1``
                                  done







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jul 28 '14 at 8:49









                                Doorknob

                                298316




                                298316










                                answered Jul 28 '14 at 6:34









                                Dishank Jindal

                                422214




                                422214











                                • This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:24










                                • you can check the updated answer.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:43










                                • Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:49











                                • the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:52
















                                • This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:24










                                • you can check the updated answer.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:43










                                • Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                  – Boris the Spider
                                  Jul 28 '14 at 8:49











                                • the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                  – Dishank Jindal
                                  Jul 28 '14 at 8:52















                                This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                – Boris the Spider
                                Jul 28 '14 at 8:24




                                This would seem to move 0 to 00 then 1 to 00 then 2 to 00 and so forth. I don't think this is correct.
                                – Boris the Spider
                                Jul 28 '14 at 8:24












                                you can check the updated answer.
                                – Dishank Jindal
                                Jul 28 '14 at 8:43




                                you can check the updated answer.
                                – Dishank Jindal
                                Jul 28 '14 at 8:43












                                Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                – Boris the Spider
                                Jul 28 '14 at 8:49





                                Fine, it should now produce the right outcome. But it should be obvious that you don't need to move anything higher than 9 as it will already have two digits. It should also be obvious that you only need to move x to 0x, rather than having two iterators. Finally you have a .mp3 missing. I think this answer is far from ideal.
                                – Boris the Spider
                                Jul 28 '14 at 8:49













                                the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                – Dishank Jindal
                                Jul 28 '14 at 8:52




                                the program is simple and will take care of all the files. And yes you are also right. i just trying to help.
                                – Dishank Jindal
                                Jul 28 '14 at 8:52


                                Popular posts from this blog

                                pylint3 and pip3 broken

                                Missing snmpget and snmpwalk

                                How to enroll fingerprints to Ubuntu 17.10 with VFS491