change multiple file name with script and use the previous names

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








up vote
-2
down vote

favorite












I want to change multiple file names with their previous names using a script, for example change file names as below:





2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt 
2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt









share|improve this question



























    up vote
    -2
    down vote

    favorite












    I want to change multiple file names with their previous names using a script, for example change file names as below:





    2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt 
    2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
    2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
    2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt









    share|improve this question

























      up vote
      -2
      down vote

      favorite









      up vote
      -2
      down vote

      favorite











      I want to change multiple file names with their previous names using a script, for example change file names as below:





      2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt 
      2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
      2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
      2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt









      share|improve this question















      I want to change multiple file names with their previous names using a script, for example change file names as below:





      2015-08-25___LSA_SP_E_txt ---> 20150825.IT.SPE.LSA.txt 
      2015-08-25___HSB_BH_Z_txt ---> 20150825.IT.BHZ.HSB.txt
      2015-08-25___TEH_SP_N_txt ---> 20150825.IT.SPN.TEH.txt
      2015-08-25___ANJ_BH_E_txt ---> 20150825.IT.BHE.ANJ.txt






      command-line bash scripts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 13 at 12:59









      dessert

      20k55795




      20k55795










      asked Feb 13 at 12:22









      MN65

      11




      11




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          One way with rename:



          rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *


          In -nono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.



          An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:



          rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *


          Example run



          $ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
          rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
          rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
          rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
          rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)





          share|improve this answer





























            up vote
            2
            down vote













            Bash script(script.sh) to rename multiple files.



            #!/bin/bash
            INPUT="$1"
            IFS=,
            [ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
            while read old_name new_name
            do
            rename "$old_name" "$new_name" # mv or rename
            done < "$INPUT"


            Input.txt file format:



            old_name1.txt,new_name1.txt
            old_name2.txt,new_name2.txt


            Use:



            bash script.sh input.txt





            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "89"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1005789%2fchange-multiple-file-name-with-script-and-use-the-previous-names%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote



              accepted










              One way with rename:



              rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *


              In -nono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.



              An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:



              rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *


              Example run



              $ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
              rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
              rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
              rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
              rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)





              share|improve this answer


























                up vote
                2
                down vote



                accepted










                One way with rename:



                rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *


                In -nono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.



                An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:



                rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *


                Example run



                $ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
                rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
                rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
                rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
                rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)





                share|improve this answer
























                  up vote
                  2
                  down vote



                  accepted







                  up vote
                  2
                  down vote



                  accepted






                  One way with rename:



                  rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *


                  In -nono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.



                  An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:



                  rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *


                  Example run



                  $ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
                  rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
                  rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
                  rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
                  rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)





                  share|improve this answer














                  One way with rename:



                  rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *


                  In -nono mode this only prints the changes, remove this flag to perform the renaming. The first expression just removes every hyphen, the second one saves the strings and replaces the underscore part.



                  An alternative is to save just everything you need in groups, this way you can also quickly change e.g. the date:



                  rename -n 's/(d*)-(d*)-(d*)___(w*)_(w*)_(w*)_/$1$2$3.IT.$5$6.$4./' *


                  Example run



                  $ rename -n 's/-//g;s/___(w*)_(w*)_(w*)_/.IT.$2$3.$1./' *
                  rename(2015-08-25___ANJ_BH_E_txt, 20150825.IT.BHE.ANJ.txt)
                  rename(2015-08-25___HSB_BH_Z_txt, 20150825.IT.BHZ.HSB.txt)
                  rename(2015-08-25___LSA_SP_E_txt, 20150825.IT.SPE.LSA.txt)
                  rename(2015-08-25___TEH_SP_N_txt, 20150825.IT.SPN.TEH.txt)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 13 at 13:37

























                  answered Feb 13 at 12:51









                  dessert

                  20k55795




                  20k55795






















                      up vote
                      2
                      down vote













                      Bash script(script.sh) to rename multiple files.



                      #!/bin/bash
                      INPUT="$1"
                      IFS=,
                      [ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
                      while read old_name new_name
                      do
                      rename "$old_name" "$new_name" # mv or rename
                      done < "$INPUT"


                      Input.txt file format:



                      old_name1.txt,new_name1.txt
                      old_name2.txt,new_name2.txt


                      Use:



                      bash script.sh input.txt





                      share|improve this answer


























                        up vote
                        2
                        down vote













                        Bash script(script.sh) to rename multiple files.



                        #!/bin/bash
                        INPUT="$1"
                        IFS=,
                        [ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
                        while read old_name new_name
                        do
                        rename "$old_name" "$new_name" # mv or rename
                        done < "$INPUT"


                        Input.txt file format:



                        old_name1.txt,new_name1.txt
                        old_name2.txt,new_name2.txt


                        Use:



                        bash script.sh input.txt





                        share|improve this answer
























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          Bash script(script.sh) to rename multiple files.



                          #!/bin/bash
                          INPUT="$1"
                          IFS=,
                          [ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
                          while read old_name new_name
                          do
                          rename "$old_name" "$new_name" # mv or rename
                          done < "$INPUT"


                          Input.txt file format:



                          old_name1.txt,new_name1.txt
                          old_name2.txt,new_name2.txt


                          Use:



                          bash script.sh input.txt





                          share|improve this answer














                          Bash script(script.sh) to rename multiple files.



                          #!/bin/bash
                          INPUT="$1"
                          IFS=,
                          [ ! -f "$INPUT" ] && echo "$INPUT file not found"; exit 99;
                          while read old_name new_name
                          do
                          rename "$old_name" "$new_name" # mv or rename
                          done < "$INPUT"


                          Input.txt file format:



                          old_name1.txt,new_name1.txt
                          old_name2.txt,new_name2.txt


                          Use:



                          bash script.sh input.txt






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 13 at 14:12









                          terdon♦

                          62.2k12128205




                          62.2k12128205










                          answered Feb 13 at 12:27









                          arupgsh

                          25217




                          25217



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1005789%2fchange-multiple-file-name-with-script-and-use-the-previous-names%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              pylint3 and pip3 broken

                              Missing snmpget and snmpwalk

                              How to enroll fingerprints to Ubuntu 17.10 with VFS491