debian rename regex to alter filename





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















sort of stuck here. I have pictures in a directory on debian (stretch, rename installed; with nextcloud running on it) with photos from one skiing trip, taken from my phone (Android Moto G5, filenames IMG_20190202...) and my girlfriend's phone (iPhone 5, filenames 19-02-02...). Since nextcloud can't sort by exif-data, it makes sense to have a constant photo-naming scheme to sort by this (and thereby by date). I figured I'd like to use rename , but can't figure out how to reach the following:



19-02-02 16-05-45 4094.jpg => IMG_20190202_160545 4094.jpg



(the suffix number, e.g. "4094", is supposed to stay to see at first glance who took the picture)



problems:



a) insert IMG_20 where there is none. This already throws me off, since rename -n 's/[^IMG_]/IMG_20/' 19-02-02 16-05-45 4094.jpg produces IMG_209-02-02 16-05-45 4094.jpg (with the 1of 2019missing). How do alter the replacement to include the first character it finds?



b) remove all occurences of - and replace the first spacewith -. No idea how about to do this...



Any help is appreciated!



EDIT:



I have found sort of a solution. But it consists of three steps (and a fourth one is needed, I'm afraid):



1) rename -n 's/^([^IMG_])/IMG_20$1/' *.jpg



2) rename -n 's/-//g' *.jpg



3) rename -n 's/ /_/' *.jpg



NEW PROBLEM: nextcloud (or windows explorer) still doesn't sort correctly, since the images taken by the Moto have 3 digits added to the TIME, e.g. a picture taken at 13h06min47sec. is called ...130547123.jpg. This is a larger number than ...200510... for example (a picture taken on 20h05min10sec), hence it is listed later. So I need a regex to delete the three digits in pos. 20,21,22 in these files! But in the iPhone pictures, this would delete the four digit group that makes it possible to distinguish between pictures taken by the Moto and pictures taken by the iPhone... :-(










share|improve this question































    0















    sort of stuck here. I have pictures in a directory on debian (stretch, rename installed; with nextcloud running on it) with photos from one skiing trip, taken from my phone (Android Moto G5, filenames IMG_20190202...) and my girlfriend's phone (iPhone 5, filenames 19-02-02...). Since nextcloud can't sort by exif-data, it makes sense to have a constant photo-naming scheme to sort by this (and thereby by date). I figured I'd like to use rename , but can't figure out how to reach the following:



    19-02-02 16-05-45 4094.jpg => IMG_20190202_160545 4094.jpg



    (the suffix number, e.g. "4094", is supposed to stay to see at first glance who took the picture)



    problems:



    a) insert IMG_20 where there is none. This already throws me off, since rename -n 's/[^IMG_]/IMG_20/' 19-02-02 16-05-45 4094.jpg produces IMG_209-02-02 16-05-45 4094.jpg (with the 1of 2019missing). How do alter the replacement to include the first character it finds?



    b) remove all occurences of - and replace the first spacewith -. No idea how about to do this...



    Any help is appreciated!



    EDIT:



    I have found sort of a solution. But it consists of three steps (and a fourth one is needed, I'm afraid):



    1) rename -n 's/^([^IMG_])/IMG_20$1/' *.jpg



    2) rename -n 's/-//g' *.jpg



    3) rename -n 's/ /_/' *.jpg



    NEW PROBLEM: nextcloud (or windows explorer) still doesn't sort correctly, since the images taken by the Moto have 3 digits added to the TIME, e.g. a picture taken at 13h06min47sec. is called ...130547123.jpg. This is a larger number than ...200510... for example (a picture taken on 20h05min10sec), hence it is listed later. So I need a regex to delete the three digits in pos. 20,21,22 in these files! But in the iPhone pictures, this would delete the four digit group that makes it possible to distinguish between pictures taken by the Moto and pictures taken by the iPhone... :-(










    share|improve this question



























      0












      0








      0








      sort of stuck here. I have pictures in a directory on debian (stretch, rename installed; with nextcloud running on it) with photos from one skiing trip, taken from my phone (Android Moto G5, filenames IMG_20190202...) and my girlfriend's phone (iPhone 5, filenames 19-02-02...). Since nextcloud can't sort by exif-data, it makes sense to have a constant photo-naming scheme to sort by this (and thereby by date). I figured I'd like to use rename , but can't figure out how to reach the following:



      19-02-02 16-05-45 4094.jpg => IMG_20190202_160545 4094.jpg



      (the suffix number, e.g. "4094", is supposed to stay to see at first glance who took the picture)



      problems:



      a) insert IMG_20 where there is none. This already throws me off, since rename -n 's/[^IMG_]/IMG_20/' 19-02-02 16-05-45 4094.jpg produces IMG_209-02-02 16-05-45 4094.jpg (with the 1of 2019missing). How do alter the replacement to include the first character it finds?



      b) remove all occurences of - and replace the first spacewith -. No idea how about to do this...



      Any help is appreciated!



      EDIT:



      I have found sort of a solution. But it consists of three steps (and a fourth one is needed, I'm afraid):



      1) rename -n 's/^([^IMG_])/IMG_20$1/' *.jpg



      2) rename -n 's/-//g' *.jpg



      3) rename -n 's/ /_/' *.jpg



      NEW PROBLEM: nextcloud (or windows explorer) still doesn't sort correctly, since the images taken by the Moto have 3 digits added to the TIME, e.g. a picture taken at 13h06min47sec. is called ...130547123.jpg. This is a larger number than ...200510... for example (a picture taken on 20h05min10sec), hence it is listed later. So I need a regex to delete the three digits in pos. 20,21,22 in these files! But in the iPhone pictures, this would delete the four digit group that makes it possible to distinguish between pictures taken by the Moto and pictures taken by the iPhone... :-(










      share|improve this question
















      sort of stuck here. I have pictures in a directory on debian (stretch, rename installed; with nextcloud running on it) with photos from one skiing trip, taken from my phone (Android Moto G5, filenames IMG_20190202...) and my girlfriend's phone (iPhone 5, filenames 19-02-02...). Since nextcloud can't sort by exif-data, it makes sense to have a constant photo-naming scheme to sort by this (and thereby by date). I figured I'd like to use rename , but can't figure out how to reach the following:



      19-02-02 16-05-45 4094.jpg => IMG_20190202_160545 4094.jpg



      (the suffix number, e.g. "4094", is supposed to stay to see at first glance who took the picture)



      problems:



      a) insert IMG_20 where there is none. This already throws me off, since rename -n 's/[^IMG_]/IMG_20/' 19-02-02 16-05-45 4094.jpg produces IMG_209-02-02 16-05-45 4094.jpg (with the 1of 2019missing). How do alter the replacement to include the first character it finds?



      b) remove all occurences of - and replace the first spacewith -. No idea how about to do this...



      Any help is appreciated!



      EDIT:



      I have found sort of a solution. But it consists of three steps (and a fourth one is needed, I'm afraid):



      1) rename -n 's/^([^IMG_])/IMG_20$1/' *.jpg



      2) rename -n 's/-//g' *.jpg



      3) rename -n 's/ /_/' *.jpg



      NEW PROBLEM: nextcloud (or windows explorer) still doesn't sort correctly, since the images taken by the Moto have 3 digits added to the TIME, e.g. a picture taken at 13h06min47sec. is called ...130547123.jpg. This is a larger number than ...200510... for example (a picture taken on 20h05min10sec), hence it is listed later. So I need a regex to delete the three digits in pos. 20,21,22 in these files! But in the iPhone pictures, this would delete the four digit group that makes it possible to distinguish between pictures taken by the Moto and pictures taken by the iPhone... :-(







      linux bash debian regex rename






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 11 at 21:28







      Beres

















      asked Feb 11 at 19:26









      BeresBeres

      12




      12






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404562%2fdebian-rename-regex-to-alter-filename%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1404562%2fdebian-rename-regex-to-alter-filename%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Сан-Квентин

          Алькесар

          Josef Freinademetz