Rename a specific component of filename from lowercase to uppercase

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











up vote
0
down vote

favorite












I have a directory with several files named as follow:



London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
London_qle_obs
Paris_qle_merged
Tokyo_qle_merged


How can I rename the file having *merged in the filename as follow:



London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged


I know that I could do a loop as follow:



for name in Paris London Tokyo do;
mv $name_qle_merged $name_Qle_merged
done


but is there no other way?







share|improve this question


























    up vote
    0
    down vote

    favorite












    I have a directory with several files named as follow:



    London_qle_merged
    Paris_qle_merged
    Tokyo_qle_merged
    London_qle_obs
    Paris_qle_merged
    Tokyo_qle_merged


    How can I rename the file having *merged in the filename as follow:



    London_Qle_merged
    Paris_Qle_merged
    Tokyo_Qle_merged


    I know that I could do a loop as follow:



    for name in Paris London Tokyo do;
    mv $name_qle_merged $name_Qle_merged
    done


    but is there no other way?







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a directory with several files named as follow:



      London_qle_merged
      Paris_qle_merged
      Tokyo_qle_merged
      London_qle_obs
      Paris_qle_merged
      Tokyo_qle_merged


      How can I rename the file having *merged in the filename as follow:



      London_Qle_merged
      Paris_Qle_merged
      Tokyo_Qle_merged


      I know that I could do a loop as follow:



      for name in Paris London Tokyo do;
      mv $name_qle_merged $name_Qle_merged
      done


      but is there no other way?







      share|improve this question














      I have a directory with several files named as follow:



      London_qle_merged
      Paris_qle_merged
      Tokyo_qle_merged
      London_qle_obs
      Paris_qle_merged
      Tokyo_qle_merged


      How can I rename the file having *merged in the filename as follow:



      London_Qle_merged
      Paris_Qle_merged
      Tokyo_Qle_merged


      I know that I could do a loop as follow:



      for name in Paris London Tokyo do;
      mv $name_qle_merged $name_Qle_merged
      done


      but is there no other way?









      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 31 at 20:13









      user1404316

      2,314520




      2,314520










      asked Jan 31 at 15:39









      steve

      328211




      328211




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Sure. In ksh/Bash/zsh:



          for f in *_merged; do
          mv -- "$f" "$f/_qle_/_Qle_"
          done


          or in standard shell.



          for f in *_qle_merged; do
          mv -- "$f" "$f%_qle_merged_Qle_merged"
          done


          See also, e.g. Parameter Expansion in BashGuide






          share|improve this answer



























            up vote
            0
            down vote













            I have done this by combination of awk and tr



            Command



            find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh


            Below merged files



            London_qle_merged
            Paris_qle_merged
            Tokyo_qle_merged


            renamed to



            London_Qle_merged
            Paris_Qle_merged
            Tokyo_Qle_merged





            share|improve this answer



























              up vote
              0
              down vote













              This will do the job with no script loops, spawning just a single sub-process:



              rename 's/qle/Qle/' *_merged





              share|improve this answer



























                up vote
                0
                down vote













                The rename command is your friend here. It is sed for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).



                The following answer is for file content, and thus uses sed. I have used it and re-purposed it to rename.
                https://unix.stackexchange.com/a/211579/4778



                rename -e 's/_(.)/_u$1/' *_merged


                It up cases the letter immediately following the first _.



                A simpler solution for this specific input



                rename 's/qle/Qle/' *_merged





                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%2f420988%2frename-a-specific-component-of-filename-from-lowercase-to-uppercase%23new-answer', 'question_page');

                  );

                  Post as a guest






























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  2
                  down vote



                  accepted










                  Sure. In ksh/Bash/zsh:



                  for f in *_merged; do
                  mv -- "$f" "$f/_qle_/_Qle_"
                  done


                  or in standard shell.



                  for f in *_qle_merged; do
                  mv -- "$f" "$f%_qle_merged_Qle_merged"
                  done


                  See also, e.g. Parameter Expansion in BashGuide






                  share|improve this answer
























                    up vote
                    2
                    down vote



                    accepted










                    Sure. In ksh/Bash/zsh:



                    for f in *_merged; do
                    mv -- "$f" "$f/_qle_/_Qle_"
                    done


                    or in standard shell.



                    for f in *_qle_merged; do
                    mv -- "$f" "$f%_qle_merged_Qle_merged"
                    done


                    See also, e.g. Parameter Expansion in BashGuide






                    share|improve this answer






















                      up vote
                      2
                      down vote



                      accepted







                      up vote
                      2
                      down vote



                      accepted






                      Sure. In ksh/Bash/zsh:



                      for f in *_merged; do
                      mv -- "$f" "$f/_qle_/_Qle_"
                      done


                      or in standard shell.



                      for f in *_qle_merged; do
                      mv -- "$f" "$f%_qle_merged_Qle_merged"
                      done


                      See also, e.g. Parameter Expansion in BashGuide






                      share|improve this answer












                      Sure. In ksh/Bash/zsh:



                      for f in *_merged; do
                      mv -- "$f" "$f/_qle_/_Qle_"
                      done


                      or in standard shell.



                      for f in *_qle_merged; do
                      mv -- "$f" "$f%_qle_merged_Qle_merged"
                      done


                      See also, e.g. Parameter Expansion in BashGuide







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 31 at 15:42









                      ilkkachu

                      49.8k674137




                      49.8k674137






















                          up vote
                          0
                          down vote













                          I have done this by combination of awk and tr



                          Command



                          find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh


                          Below merged files



                          London_qle_merged
                          Paris_qle_merged
                          Tokyo_qle_merged


                          renamed to



                          London_Qle_merged
                          Paris_Qle_merged
                          Tokyo_Qle_merged





                          share|improve this answer
























                            up vote
                            0
                            down vote













                            I have done this by combination of awk and tr



                            Command



                            find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh


                            Below merged files



                            London_qle_merged
                            Paris_qle_merged
                            Tokyo_qle_merged


                            renamed to



                            London_Qle_merged
                            Paris_Qle_merged
                            Tokyo_Qle_merged





                            share|improve this answer






















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              I have done this by combination of awk and tr



                              Command



                              find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh


                              Below merged files



                              London_qle_merged
                              Paris_qle_merged
                              Tokyo_qle_merged


                              renamed to



                              London_Qle_merged
                              Paris_Qle_merged
                              Tokyo_Qle_merged





                              share|improve this answer












                              I have done this by combination of awk and tr



                              Command



                              find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh


                              Below merged files



                              London_qle_merged
                              Paris_qle_merged
                              Tokyo_qle_merged


                              renamed to



                              London_Qle_merged
                              Paris_Qle_merged
                              Tokyo_Qle_merged






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 31 at 18:52









                              Praveen Kumar BS

                              1,010128




                              1,010128




















                                  up vote
                                  0
                                  down vote













                                  This will do the job with no script loops, spawning just a single sub-process:



                                  rename 's/qle/Qle/' *_merged





                                  share|improve this answer
























                                    up vote
                                    0
                                    down vote













                                    This will do the job with no script loops, spawning just a single sub-process:



                                    rename 's/qle/Qle/' *_merged





                                    share|improve this answer






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      This will do the job with no script loops, spawning just a single sub-process:



                                      rename 's/qle/Qle/' *_merged





                                      share|improve this answer












                                      This will do the job with no script loops, spawning just a single sub-process:



                                      rename 's/qle/Qle/' *_merged






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 31 at 19:09









                                      user1404316

                                      2,314520




                                      2,314520




















                                          up vote
                                          0
                                          down vote













                                          The rename command is your friend here. It is sed for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).



                                          The following answer is for file content, and thus uses sed. I have used it and re-purposed it to rename.
                                          https://unix.stackexchange.com/a/211579/4778



                                          rename -e 's/_(.)/_u$1/' *_merged


                                          It up cases the letter immediately following the first _.



                                          A simpler solution for this specific input



                                          rename 's/qle/Qle/' *_merged





                                          share|improve this answer
























                                            up vote
                                            0
                                            down vote













                                            The rename command is your friend here. It is sed for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).



                                            The following answer is for file content, and thus uses sed. I have used it and re-purposed it to rename.
                                            https://unix.stackexchange.com/a/211579/4778



                                            rename -e 's/_(.)/_u$1/' *_merged


                                            It up cases the letter immediately following the first _.



                                            A simpler solution for this specific input



                                            rename 's/qle/Qle/' *_merged





                                            share|improve this answer






















                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              The rename command is your friend here. It is sed for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).



                                              The following answer is for file content, and thus uses sed. I have used it and re-purposed it to rename.
                                              https://unix.stackexchange.com/a/211579/4778



                                              rename -e 's/_(.)/_u$1/' *_merged


                                              It up cases the letter immediately following the first _.



                                              A simpler solution for this specific input



                                              rename 's/qle/Qle/' *_merged





                                              share|improve this answer












                                              The rename command is your friend here. It is sed for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).



                                              The following answer is for file content, and thus uses sed. I have used it and re-purposed it to rename.
                                              https://unix.stackexchange.com/a/211579/4778



                                              rename -e 's/_(.)/_u$1/' *_merged


                                              It up cases the letter immediately following the first _.



                                              A simpler solution for this specific input



                                              rename 's/qle/Qle/' *_merged






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Jan 31 at 19:19









                                              ctrl-alt-delor

                                              8,79031947




                                              8,79031947






















                                                   

                                                  draft saved


                                                  draft discarded


























                                                   


                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420988%2frename-a-specific-component-of-filename-from-lowercase-to-uppercase%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest













































































                                                  Popular posts from this blog

                                                  How to check contact read email or not when send email to Individual?

                                                  Displaying single band from multi-band raster using QGIS

                                                  How many registers does an x86_64 CPU actually have?