Remove the second instance of a character from a stringRemove branch from all submodulessed + how to delete...

The economy of trapping

Dark side of an exoplanet - if it was earth-like would its surface light be detectable?

What is the hex versus octal timeline?

Potential new partner angry about first collaboration - how to answer email to close up this encounter in a graceful manner

How to create a summation symbol with a vertical bar?

How to analyze "dearly beloved"?

Does Git delete empty folders?

Is it safe to remove the bottom chords of a series of garage roof trusses?

What is "Wayfinder's Guide to Eberron"?

How can I support the recycling, but not the new production of aluminum?

Why my earth simulation is slower than the reality?

Why were movies shot on film shot at 24 frames per second?

Vacuum collapse -- why do strong metals implode but glass doesn't?

Efficiently pathfinding many flocking enemies around obstacles

Was 'help' pronounced starting with a vowel sound?

Why don't we use Cavea-B

Are required indicators necessary for radio buttons?

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Have only girls been born for a long time in this village?

How to setup a teletype to a unix shell

How to persuade recruiters to send me the Job Description?

How to specify and fit a hybrid machine learning - linear model

Injectivity radius of manifolds with boundary

Most practical knots for hitching a line to an object while keeping the bitter end as tight as possible, without sag?



Remove the second instance of a character from a string


Remove branch from all submodulessed + how to delete the second character “.” from the lineHow can I insert the contents of a file into a string in bashSearch for matching files with wildcards without using find in a bash scriptGrep for regex in basename but return wholenameRemove character from string at specific locationConfused about the behavior of asterisk in ls commandHow to automatically append a command to a file when called in a shell?wget -i notifying when each file finishes (for processing purposes)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I am working on making a git command I use more useful. A common task I do is to grep my git rev-list --all. I wrote (aka cut and pasted another StackExchange answer) git command to do this for me.



~/bin/git-search:



!/bin/bash
function _search() {
git rev-list --all | (
while read revision; do
git grep -F $1 $revision
done
)
}
_search $1


The output from this looks like:



f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py:grepped string



I usually take these results and run git show along with the commit and file path to see that particular version of the file. git show takes the input of {COMMIT HASH}:path/to/file.



What I'd ideally like is to have my git function stick a whitespace where the second : is, which would allow me more easily copy and paste the output of git-search into git show, ie:



f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py grepped string



I'd like to use BASH for this as I am already using BASH. My initial solution was to use Python but that seems needless to me. I just am not sure how best to achieve this in BASH.










share|improve this question































    0















    I am working on making a git command I use more useful. A common task I do is to grep my git rev-list --all. I wrote (aka cut and pasted another StackExchange answer) git command to do this for me.



    ~/bin/git-search:



    !/bin/bash
    function _search() {
    git rev-list --all | (
    while read revision; do
    git grep -F $1 $revision
    done
    )
    }
    _search $1


    The output from this looks like:



    f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py:grepped string



    I usually take these results and run git show along with the commit and file path to see that particular version of the file. git show takes the input of {COMMIT HASH}:path/to/file.



    What I'd ideally like is to have my git function stick a whitespace where the second : is, which would allow me more easily copy and paste the output of git-search into git show, ie:



    f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py grepped string



    I'd like to use BASH for this as I am already using BASH. My initial solution was to use Python but that seems needless to me. I just am not sure how best to achieve this in BASH.










    share|improve this question



























      0












      0








      0








      I am working on making a git command I use more useful. A common task I do is to grep my git rev-list --all. I wrote (aka cut and pasted another StackExchange answer) git command to do this for me.



      ~/bin/git-search:



      !/bin/bash
      function _search() {
      git rev-list --all | (
      while read revision; do
      git grep -F $1 $revision
      done
      )
      }
      _search $1


      The output from this looks like:



      f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py:grepped string



      I usually take these results and run git show along with the commit and file path to see that particular version of the file. git show takes the input of {COMMIT HASH}:path/to/file.



      What I'd ideally like is to have my git function stick a whitespace where the second : is, which would allow me more easily copy and paste the output of git-search into git show, ie:



      f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py grepped string



      I'd like to use BASH for this as I am already using BASH. My initial solution was to use Python but that seems needless to me. I just am not sure how best to achieve this in BASH.










      share|improve this question














      I am working on making a git command I use more useful. A common task I do is to grep my git rev-list --all. I wrote (aka cut and pasted another StackExchange answer) git command to do this for me.



      ~/bin/git-search:



      !/bin/bash
      function _search() {
      git rev-list --all | (
      while read revision; do
      git grep -F $1 $revision
      done
      )
      }
      _search $1


      The output from this looks like:



      f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py:grepped string



      I usually take these results and run git show along with the commit and file path to see that particular version of the file. git show takes the input of {COMMIT HASH}:path/to/file.



      What I'd ideally like is to have my git function stick a whitespace where the second : is, which would allow me more easily copy and paste the output of git-search into git show, ie:



      f26ce56cf6b17401292c494f906b2b6a9071ca75:filename.py grepped string



      I'd like to use BASH for this as I am already using BASH. My initial solution was to use Python but that seems needless to me. I just am not sure how best to achieve this in BASH.







      bash git






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Ian PringleIan Pringle

      121 silver badge3 bronze badges




      121 silver badge3 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          sed 's/:/ /2'


          This would change the second : character to a space.



          You could stick that in as an extra stage of your function's pipeline:



          #!/bin/sh

          git rev-list --all |
          while read revision; do
          git grep -F "$1" "$revision"
          done |
          sed 's/:/ /2'



          (I actually deleted the function as it didn't seem to be needed; note also the quoting of the variable expansions; oh, and it's a /bin/sh script since it's not using any bash-specific features (neither did yours, except for the unneeded function keyword))






          share|improve this answer




























          • That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

            – Ian Pringle
            2 days ago











          • @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

            – Kusalananda
            2 days ago













          • @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

            – Ian Pringle
            2 days ago














          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2funix.stackexchange.com%2fquestions%2f536167%2fremove-the-second-instance-of-a-character-from-a-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          sed 's/:/ /2'


          This would change the second : character to a space.



          You could stick that in as an extra stage of your function's pipeline:



          #!/bin/sh

          git rev-list --all |
          while read revision; do
          git grep -F "$1" "$revision"
          done |
          sed 's/:/ /2'



          (I actually deleted the function as it didn't seem to be needed; note also the quoting of the variable expansions; oh, and it's a /bin/sh script since it's not using any bash-specific features (neither did yours, except for the unneeded function keyword))






          share|improve this answer




























          • That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

            – Ian Pringle
            2 days ago











          • @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

            – Kusalananda
            2 days ago













          • @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

            – Ian Pringle
            2 days ago
















          1














          sed 's/:/ /2'


          This would change the second : character to a space.



          You could stick that in as an extra stage of your function's pipeline:



          #!/bin/sh

          git rev-list --all |
          while read revision; do
          git grep -F "$1" "$revision"
          done |
          sed 's/:/ /2'



          (I actually deleted the function as it didn't seem to be needed; note also the quoting of the variable expansions; oh, and it's a /bin/sh script since it's not using any bash-specific features (neither did yours, except for the unneeded function keyword))






          share|improve this answer




























          • That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

            – Ian Pringle
            2 days ago











          • @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

            – Kusalananda
            2 days ago













          • @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

            – Ian Pringle
            2 days ago














          1












          1








          1







          sed 's/:/ /2'


          This would change the second : character to a space.



          You could stick that in as an extra stage of your function's pipeline:



          #!/bin/sh

          git rev-list --all |
          while read revision; do
          git grep -F "$1" "$revision"
          done |
          sed 's/:/ /2'



          (I actually deleted the function as it didn't seem to be needed; note also the quoting of the variable expansions; oh, and it's a /bin/sh script since it's not using any bash-specific features (neither did yours, except for the unneeded function keyword))






          share|improve this answer















          sed 's/:/ /2'


          This would change the second : character to a space.



          You could stick that in as an extra stage of your function's pipeline:



          #!/bin/sh

          git rev-list --all |
          while read revision; do
          git grep -F "$1" "$revision"
          done |
          sed 's/:/ /2'



          (I actually deleted the function as it didn't seem to be needed; note also the quoting of the variable expansions; oh, and it's a /bin/sh script since it's not using any bash-specific features (neither did yours, except for the unneeded function keyword))







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          KusalanandaKusalananda

          160k18 gold badges316 silver badges503 bronze badges




          160k18 gold badges316 silver badges503 bronze badges
















          • That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

            – Ian Pringle
            2 days ago











          • @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

            – Kusalananda
            2 days ago













          • @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

            – Ian Pringle
            2 days ago



















          • That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

            – Ian Pringle
            2 days ago











          • @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

            – Kusalananda
            2 days ago













          • @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

            – Ian Pringle
            2 days ago

















          That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

          – Ian Pringle
          2 days ago





          That's perfect! And thanks for the other improvements as well. I wasn't aware sed could do this. Does that mean I can swap out the 2 for a 3 to remove the third instance? I only knew about d, e, and g. Guess I have a lot of sed to learn still.

          – Ian Pringle
          2 days ago













          @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

          – Kusalananda
          2 days ago







          @IanPringle Yes, you can swap out the 2 for 3 or any other positive integer. There is no d flag to the s command in sed (not even in GNU sed). I assume that you're thinking about the d commad in sed.

          – Kusalananda
          2 days ago















          @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

          – Ian Pringle
          2 days ago





          @kusalanada That's great! Yes, I guess that's true the d replaces the s. Thanks again!

          – Ian Pringle
          2 days ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • 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%2funix.stackexchange.com%2fquestions%2f536167%2fremove-the-second-instance-of-a-character-from-a-string%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

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...