Removing first forward slash from string

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











up vote
-1
down vote

favorite












I'm trying to remove the first / from a string in a shell script.



For example




file:///path/to/file




and output to




file://path/to/file











share|improve this question









New contributor




hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    -1
    down vote

    favorite












    I'm trying to remove the first / from a string in a shell script.



    For example




    file:///path/to/file




    and output to




    file://path/to/file











    share|improve this question









    New contributor




    hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I'm trying to remove the first / from a string in a shell script.



      For example




      file:///path/to/file




      and output to




      file://path/to/file











      share|improve this question









      New contributor




      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm trying to remove the first / from a string in a shell script.



      For example




      file:///path/to/file




      and output to




      file://path/to/file








      bash regular-expression






      share|improve this question









      New contributor




      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 3 hours ago









      Rui F Ribeiro

      38k1475123




      38k1475123






      New contributor




      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      hugovdd

      11




      11




      New contributor




      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      hugovdd is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          If the string is in a shell variable, then you can use shell parameter expansion:



          $ var='file:///path/to/file'

          $ echo "$var///"
          file://path/to/file





          share|improve this answer




















          • IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
            – bgregs
            3 hours ago


















          up vote
          0
          down vote













          Something like will do the work:



          A="file:///path/to/file"
          B=$(echo $A|sed 's@/@@')


          without g at the end in sed the program will change only first occurrence






          share|improve this answer



























            up vote
            0
            down vote













            Here is a cheat sheet for various way of doing that with some fundamentals.
            https://devhints.io/bash






            share|improve this answer
















            • 1




              While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
              – Anthony Geoghegan
              2 hours 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',
            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
            );



            );






            hugovdd is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480846%2fremoving-first-forward-slash-from-string%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            If the string is in a shell variable, then you can use shell parameter expansion:



            $ var='file:///path/to/file'

            $ echo "$var///"
            file://path/to/file





            share|improve this answer




















            • IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
              – bgregs
              3 hours ago















            up vote
            2
            down vote



            accepted










            If the string is in a shell variable, then you can use shell parameter expansion:



            $ var='file:///path/to/file'

            $ echo "$var///"
            file://path/to/file





            share|improve this answer




















            • IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
              – bgregs
              3 hours ago













            up vote
            2
            down vote



            accepted







            up vote
            2
            down vote



            accepted






            If the string is in a shell variable, then you can use shell parameter expansion:



            $ var='file:///path/to/file'

            $ echo "$var///"
            file://path/to/file





            share|improve this answer












            If the string is in a shell variable, then you can use shell parameter expansion:



            $ var='file:///path/to/file'

            $ echo "$var///"
            file://path/to/file






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 3 hours ago









            steeldriver

            33.4k34982




            33.4k34982











            • IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
              – bgregs
              3 hours ago

















            • IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
              – bgregs
              3 hours ago
















            IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
            – bgregs
            3 hours ago





            IMHO this is the true answer, as it doesn't rely on calls to other programs to answer the OP's question. Nicely done.
            – bgregs
            3 hours ago













            up vote
            0
            down vote













            Something like will do the work:



            A="file:///path/to/file"
            B=$(echo $A|sed 's@/@@')


            without g at the end in sed the program will change only first occurrence






            share|improve this answer
























              up vote
              0
              down vote













              Something like will do the work:



              A="file:///path/to/file"
              B=$(echo $A|sed 's@/@@')


              without g at the end in sed the program will change only first occurrence






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Something like will do the work:



                A="file:///path/to/file"
                B=$(echo $A|sed 's@/@@')


                without g at the end in sed the program will change only first occurrence






                share|improve this answer












                Something like will do the work:



                A="file:///path/to/file"
                B=$(echo $A|sed 's@/@@')


                without g at the end in sed the program will change only first occurrence







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 3 hours ago









                Romeo Ninov

                4,57431626




                4,57431626




















                    up vote
                    0
                    down vote













                    Here is a cheat sheet for various way of doing that with some fundamentals.
                    https://devhints.io/bash






                    share|improve this answer
















                    • 1




                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      – Anthony Geoghegan
                      2 hours ago














                    up vote
                    0
                    down vote













                    Here is a cheat sheet for various way of doing that with some fundamentals.
                    https://devhints.io/bash






                    share|improve this answer
















                    • 1




                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      – Anthony Geoghegan
                      2 hours ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Here is a cheat sheet for various way of doing that with some fundamentals.
                    https://devhints.io/bash






                    share|improve this answer












                    Here is a cheat sheet for various way of doing that with some fundamentals.
                    https://devhints.io/bash







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 3 hours ago









                    SkyRar

                    467




                    467







                    • 1




                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      – Anthony Geoghegan
                      2 hours ago












                    • 1




                      While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                      – Anthony Geoghegan
                      2 hours ago







                    1




                    1




                    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                    – Anthony Geoghegan
                    2 hours ago




                    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
                    – Anthony Geoghegan
                    2 hours ago










                    hugovdd is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    hugovdd is a new contributor. Be nice, and check out our Code of Conduct.












                    hugovdd is a new contributor. Be nice, and check out our Code of Conduct.











                    hugovdd is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480846%2fremoving-first-forward-slash-from-string%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos