Renaming multiple files with 2 consecutive periods within name

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











up vote
0
down vote

favorite












I need to use the rename command to rename hundreds of files which contain .. (2 periods) within the filename and change .. to - (hyphen). The fact that it contains periods seems to be confusing the rename command.



Here are some example filenames:



20180201_190000_TX_AJAX..HHE_instrument_0456 
20180201_190000_TX_AJAX..HHN_instrument_0456
20180201_190000_TX_AJAX..HHZ_instrument_0456


I need to rename these files to look linke:



20180201_190000_TX_AJAX-HHE_instrument_0456 
20180201_190000_TX_AJAX-HHN_instrument_0456
20180201_190000_TX_AJAX-HHZ_instrument_0456


This command:



rename 's/../-/' *


results in these filenames:



-180201_190000_TX_AJAX..HHE_instrument_0456 -180201_190000_TX_AJAX..HHN_instrument_0456 -180201_190000_TX_AJAX..HHZ_instrument_0456


It seems that periods have some special purpose so it's getting confused. I then tried this:



rename 's/..H/-H/' *


The AJAX in the sample represents a station and these vary. The above syntax works and results in "20180201_190000_TX_AJAX-HHE_instrument_0456" as expected for many stations but unexpected results for others:



20180201_000000_SA.AKHBR..HNE_instrument_0542 renamed as 20180201_000000_SA.-HBR..HNE_instrument_0542

20180201_000000_SA.KSHB4..HHE_instrument_0935 renamed as 20180201_000000_SA.-HB4..HHE_instrument_0935

20180201_000000_SA.HTM01..HHE_instrument_0933 renamed as 20180201_000000_S-HTM01..HHE_instrument_0933


It seems any station which contains the letter H gets confused.



For some reference, AJAX is a station code, and station codes are either 4 or 5 characters in length.



Next I tried this:



rename ‘s/SA.????..H/SA.????-H/ * -n 


but this generates an error:



"Nested quantifiers in regex; marked by <-- HERE in m/SA.??? <-- HERE ?..H/ at (eval 1) line 1."


so I guess it doesn't like wildcards.



Any help you can provide is appreciated.







share|improve this question


























    up vote
    0
    down vote

    favorite












    I need to use the rename command to rename hundreds of files which contain .. (2 periods) within the filename and change .. to - (hyphen). The fact that it contains periods seems to be confusing the rename command.



    Here are some example filenames:



    20180201_190000_TX_AJAX..HHE_instrument_0456 
    20180201_190000_TX_AJAX..HHN_instrument_0456
    20180201_190000_TX_AJAX..HHZ_instrument_0456


    I need to rename these files to look linke:



    20180201_190000_TX_AJAX-HHE_instrument_0456 
    20180201_190000_TX_AJAX-HHN_instrument_0456
    20180201_190000_TX_AJAX-HHZ_instrument_0456


    This command:



    rename 's/../-/' *


    results in these filenames:



    -180201_190000_TX_AJAX..HHE_instrument_0456 -180201_190000_TX_AJAX..HHN_instrument_0456 -180201_190000_TX_AJAX..HHZ_instrument_0456


    It seems that periods have some special purpose so it's getting confused. I then tried this:



    rename 's/..H/-H/' *


    The AJAX in the sample represents a station and these vary. The above syntax works and results in "20180201_190000_TX_AJAX-HHE_instrument_0456" as expected for many stations but unexpected results for others:



    20180201_000000_SA.AKHBR..HNE_instrument_0542 renamed as 20180201_000000_SA.-HBR..HNE_instrument_0542

    20180201_000000_SA.KSHB4..HHE_instrument_0935 renamed as 20180201_000000_SA.-HB4..HHE_instrument_0935

    20180201_000000_SA.HTM01..HHE_instrument_0933 renamed as 20180201_000000_S-HTM01..HHE_instrument_0933


    It seems any station which contains the letter H gets confused.



    For some reference, AJAX is a station code, and station codes are either 4 or 5 characters in length.



    Next I tried this:



    rename ‘s/SA.????..H/SA.????-H/ * -n 


    but this generates an error:



    "Nested quantifiers in regex; marked by <-- HERE in m/SA.??? <-- HERE ?..H/ at (eval 1) line 1."


    so I guess it doesn't like wildcards.



    Any help you can provide is appreciated.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I need to use the rename command to rename hundreds of files which contain .. (2 periods) within the filename and change .. to - (hyphen). The fact that it contains periods seems to be confusing the rename command.



      Here are some example filenames:



      20180201_190000_TX_AJAX..HHE_instrument_0456 
      20180201_190000_TX_AJAX..HHN_instrument_0456
      20180201_190000_TX_AJAX..HHZ_instrument_0456


      I need to rename these files to look linke:



      20180201_190000_TX_AJAX-HHE_instrument_0456 
      20180201_190000_TX_AJAX-HHN_instrument_0456
      20180201_190000_TX_AJAX-HHZ_instrument_0456


      This command:



      rename 's/../-/' *


      results in these filenames:



      -180201_190000_TX_AJAX..HHE_instrument_0456 -180201_190000_TX_AJAX..HHN_instrument_0456 -180201_190000_TX_AJAX..HHZ_instrument_0456


      It seems that periods have some special purpose so it's getting confused. I then tried this:



      rename 's/..H/-H/' *


      The AJAX in the sample represents a station and these vary. The above syntax works and results in "20180201_190000_TX_AJAX-HHE_instrument_0456" as expected for many stations but unexpected results for others:



      20180201_000000_SA.AKHBR..HNE_instrument_0542 renamed as 20180201_000000_SA.-HBR..HNE_instrument_0542

      20180201_000000_SA.KSHB4..HHE_instrument_0935 renamed as 20180201_000000_SA.-HB4..HHE_instrument_0935

      20180201_000000_SA.HTM01..HHE_instrument_0933 renamed as 20180201_000000_S-HTM01..HHE_instrument_0933


      It seems any station which contains the letter H gets confused.



      For some reference, AJAX is a station code, and station codes are either 4 or 5 characters in length.



      Next I tried this:



      rename ‘s/SA.????..H/SA.????-H/ * -n 


      but this generates an error:



      "Nested quantifiers in regex; marked by <-- HERE in m/SA.??? <-- HERE ?..H/ at (eval 1) line 1."


      so I guess it doesn't like wildcards.



      Any help you can provide is appreciated.







      share|improve this question














      I need to use the rename command to rename hundreds of files which contain .. (2 periods) within the filename and change .. to - (hyphen). The fact that it contains periods seems to be confusing the rename command.



      Here are some example filenames:



      20180201_190000_TX_AJAX..HHE_instrument_0456 
      20180201_190000_TX_AJAX..HHN_instrument_0456
      20180201_190000_TX_AJAX..HHZ_instrument_0456


      I need to rename these files to look linke:



      20180201_190000_TX_AJAX-HHE_instrument_0456 
      20180201_190000_TX_AJAX-HHN_instrument_0456
      20180201_190000_TX_AJAX-HHZ_instrument_0456


      This command:



      rename 's/../-/' *


      results in these filenames:



      -180201_190000_TX_AJAX..HHE_instrument_0456 -180201_190000_TX_AJAX..HHN_instrument_0456 -180201_190000_TX_AJAX..HHZ_instrument_0456


      It seems that periods have some special purpose so it's getting confused. I then tried this:



      rename 's/..H/-H/' *


      The AJAX in the sample represents a station and these vary. The above syntax works and results in "20180201_190000_TX_AJAX-HHE_instrument_0456" as expected for many stations but unexpected results for others:



      20180201_000000_SA.AKHBR..HNE_instrument_0542 renamed as 20180201_000000_SA.-HBR..HNE_instrument_0542

      20180201_000000_SA.KSHB4..HHE_instrument_0935 renamed as 20180201_000000_SA.-HB4..HHE_instrument_0935

      20180201_000000_SA.HTM01..HHE_instrument_0933 renamed as 20180201_000000_S-HTM01..HHE_instrument_0933


      It seems any station which contains the letter H gets confused.



      For some reference, AJAX is a station code, and station codes are either 4 or 5 characters in length.



      Next I tried this:



      rename ‘s/SA.????..H/SA.????-H/ * -n 


      but this generates an error:



      "Nested quantifiers in regex; marked by <-- HERE in m/SA.??? <-- HERE ?..H/ at (eval 1) line 1."


      so I guess it doesn't like wildcards.



      Any help you can provide is appreciated.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 16:54









      Gilles Quenot

      15.3k13448




      15.3k13448










      asked Mar 7 at 16:48









      Suzan Kowalski

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          Try this :



          rename -n 's/../-/' ./*


          The . character in regex, means any character, so it matches everything!



          Remove -n when you are satisfied with your tests






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f428797%2frenaming-multiple-files-with-2-consecutive-periods-within-name%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Try this :



            rename -n 's/../-/' ./*


            The . character in regex, means any character, so it matches everything!



            Remove -n when you are satisfied with your tests






            share|improve this answer


























              up vote
              2
              down vote













              Try this :



              rename -n 's/../-/' ./*


              The . character in regex, means any character, so it matches everything!



              Remove -n when you are satisfied with your tests






              share|improve this answer
























                up vote
                2
                down vote










                up vote
                2
                down vote









                Try this :



                rename -n 's/../-/' ./*


                The . character in regex, means any character, so it matches everything!



                Remove -n when you are satisfied with your tests






                share|improve this answer














                Try this :



                rename -n 's/../-/' ./*


                The . character in regex, means any character, so it matches everything!



                Remove -n when you are satisfied with your tests







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 17:14

























                answered Mar 7 at 16:55









                Gilles Quenot

                15.3k13448




                15.3k13448






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428797%2frenaming-multiple-files-with-2-consecutive-periods-within-name%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)