Replacing just the first occurence of a character in a line

Multi tool use
Multi tool use

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











up vote
4
down vote

favorite












I have a line with thousands of lines like this:



"100K";"0.00001";"10";"0.01"]
"101K";"0.0001";"100";"0.1"]
"102K";"1";"1000";"1"]
"102K";"1";"1000";"1"]
"103K";"0.01";"10000";"10"]
"104K";"0.1";"100000";"100"]
"105K";"1";"1000000";"1000"]
"109K";"0.000001";"1";"1"]
"120K";"0.000012";"12";"12"]


I want to replace the first occurrence of ; in a line with :[



Making these lines equal to



"100K":["0.00001";"10";"0.01"]
"101K":["0.0001";"100";"0.1"]
"102K":["1";"1000";"1"]
"102K":["1";"1000";"1"]
"103K":["0.01";"10000";"10"]
"104K":["0.1";"100000";"100"]
"105K":["1";"1000000";"1000"]
"109K":["0.000001";"1";"1"]
"120K":["0.000012";"12";"12"]


how do I do that with sed or other unix command?










share|improve this question



























    up vote
    4
    down vote

    favorite












    I have a line with thousands of lines like this:



    "100K";"0.00001";"10";"0.01"]
    "101K";"0.0001";"100";"0.1"]
    "102K";"1";"1000";"1"]
    "102K";"1";"1000";"1"]
    "103K";"0.01";"10000";"10"]
    "104K";"0.1";"100000";"100"]
    "105K";"1";"1000000";"1000"]
    "109K";"0.000001";"1";"1"]
    "120K";"0.000012";"12";"12"]


    I want to replace the first occurrence of ; in a line with :[



    Making these lines equal to



    "100K":["0.00001";"10";"0.01"]
    "101K":["0.0001";"100";"0.1"]
    "102K":["1";"1000";"1"]
    "102K":["1";"1000";"1"]
    "103K":["0.01";"10000";"10"]
    "104K":["0.1";"100000";"100"]
    "105K":["1";"1000000";"1000"]
    "109K":["0.000001";"1";"1"]
    "120K":["0.000012";"12";"12"]


    how do I do that with sed or other unix command?










    share|improve this question

























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have a line with thousands of lines like this:



      "100K";"0.00001";"10";"0.01"]
      "101K";"0.0001";"100";"0.1"]
      "102K";"1";"1000";"1"]
      "102K";"1";"1000";"1"]
      "103K";"0.01";"10000";"10"]
      "104K";"0.1";"100000";"100"]
      "105K";"1";"1000000";"1000"]
      "109K";"0.000001";"1";"1"]
      "120K";"0.000012";"12";"12"]


      I want to replace the first occurrence of ; in a line with :[



      Making these lines equal to



      "100K":["0.00001";"10";"0.01"]
      "101K":["0.0001";"100";"0.1"]
      "102K":["1";"1000";"1"]
      "102K":["1";"1000";"1"]
      "103K":["0.01";"10000";"10"]
      "104K":["0.1";"100000";"100"]
      "105K":["1";"1000000";"1000"]
      "109K":["0.000001";"1";"1"]
      "120K":["0.000012";"12";"12"]


      how do I do that with sed or other unix command?










      share|improve this question















      I have a line with thousands of lines like this:



      "100K";"0.00001";"10";"0.01"]
      "101K";"0.0001";"100";"0.1"]
      "102K";"1";"1000";"1"]
      "102K";"1";"1000";"1"]
      "103K";"0.01";"10000";"10"]
      "104K";"0.1";"100000";"100"]
      "105K";"1";"1000000";"1000"]
      "109K";"0.000001";"1";"1"]
      "120K";"0.000012";"12";"12"]


      I want to replace the first occurrence of ; in a line with :[



      Making these lines equal to



      "100K":["0.00001";"10";"0.01"]
      "101K":["0.0001";"100";"0.1"]
      "102K":["1";"1000";"1"]
      "102K":["1";"1000";"1"]
      "103K":["0.01";"10000";"10"]
      "104K":["0.1";"100000";"100"]
      "105K":["1";"1000000";"1000"]
      "109K":["0.000001";"1";"1"]
      "120K":["0.000012";"12";"12"]


      how do I do that with sed or other unix command?







      text-processing awk sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago









      David Foerster

      948616




      948616










      asked 9 hours ago









      SpaceDog

      1,658122851




      1,658122851




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          11
          down vote



          accepted










          sed 's/;/:[/' file

          "100K":["0.00001";"10";"0.01"]
          "101K":["0.0001";"100";"0.1"]
          "102K":["1";"1000";"1"]
          "102K":["1";"1000";"1"]
          "103K":["0.01";"10000";"10"]
          "104K":["0.1";"100000";"100"]
          "105K":["1";"1000000";"1000"]
          "109K":["0.000001";"1";"1"]
          "120K":["0.000012";"12";"12"]





          share|improve this answer
















          • 1




            if you add -i, you do it in one go.
            – Rui F Ribeiro
            9 hours ago

















          up vote
          1
          down vote













          Since you tagged the question with awk:



          awk ' sub(/;/, ":["); print; '





          share|improve this answer



























            up vote
            0
            down vote













            You can try with below 2 commands also:



            perl -pne "s/;/:[/" filename
            sed 's/;/:[/1' filename


            Output:



            "100K":["0.00001";"10";"0.01"]
            "101K":["0.0001";"100";"0.1"]
            "102K":["1";"1000";"1"]
            "102K":["1";"1000";"1"]
            "103K":["0.01";"10000";"10"]
            "104K":["0.1";"100000";"100"]
            "105K":["1";"1000000";"1000"]
            "109K":["0.000001";"1";"1"]
            "120K":["0.000012";"12";"12"]





            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%2f474287%2freplacing-just-the-first-occurence-of-a-character-in-a-line%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
              11
              down vote



              accepted










              sed 's/;/:[/' file

              "100K":["0.00001";"10";"0.01"]
              "101K":["0.0001";"100";"0.1"]
              "102K":["1";"1000";"1"]
              "102K":["1";"1000";"1"]
              "103K":["0.01";"10000";"10"]
              "104K":["0.1";"100000";"100"]
              "105K":["1";"1000000";"1000"]
              "109K":["0.000001";"1";"1"]
              "120K":["0.000012";"12";"12"]





              share|improve this answer
















              • 1




                if you add -i, you do it in one go.
                – Rui F Ribeiro
                9 hours ago














              up vote
              11
              down vote



              accepted










              sed 's/;/:[/' file

              "100K":["0.00001";"10";"0.01"]
              "101K":["0.0001";"100";"0.1"]
              "102K":["1";"1000";"1"]
              "102K":["1";"1000";"1"]
              "103K":["0.01";"10000";"10"]
              "104K":["0.1";"100000";"100"]
              "105K":["1";"1000000";"1000"]
              "109K":["0.000001";"1";"1"]
              "120K":["0.000012";"12";"12"]





              share|improve this answer
















              • 1




                if you add -i, you do it in one go.
                – Rui F Ribeiro
                9 hours ago












              up vote
              11
              down vote



              accepted







              up vote
              11
              down vote



              accepted






              sed 's/;/:[/' file

              "100K":["0.00001";"10";"0.01"]
              "101K":["0.0001";"100";"0.1"]
              "102K":["1";"1000";"1"]
              "102K":["1";"1000";"1"]
              "103K":["0.01";"10000";"10"]
              "104K":["0.1";"100000";"100"]
              "105K":["1";"1000000";"1000"]
              "109K":["0.000001";"1";"1"]
              "120K":["0.000012";"12";"12"]





              share|improve this answer












              sed 's/;/:[/' file

              "100K":["0.00001";"10";"0.01"]
              "101K":["0.0001";"100";"0.1"]
              "102K":["1";"1000";"1"]
              "102K":["1";"1000";"1"]
              "103K":["0.01";"10000";"10"]
              "104K":["0.1";"100000";"100"]
              "105K":["1";"1000000";"1000"]
              "109K":["0.000001";"1";"1"]
              "120K":["0.000012";"12";"12"]






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 9 hours ago









              Goro

              8,14153878




              8,14153878







              • 1




                if you add -i, you do it in one go.
                – Rui F Ribeiro
                9 hours ago












              • 1




                if you add -i, you do it in one go.
                – Rui F Ribeiro
                9 hours ago







              1




              1




              if you add -i, you do it in one go.
              – Rui F Ribeiro
              9 hours ago




              if you add -i, you do it in one go.
              – Rui F Ribeiro
              9 hours ago












              up vote
              1
              down vote













              Since you tagged the question with awk:



              awk ' sub(/;/, ":["); print; '





              share|improve this answer
























                up vote
                1
                down vote













                Since you tagged the question with awk:



                awk ' sub(/;/, ":["); print; '





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Since you tagged the question with awk:



                  awk ' sub(/;/, ":["); print; '





                  share|improve this answer












                  Since you tagged the question with awk:



                  awk ' sub(/;/, ":["); print; '






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 6 hours ago









                  David Foerster

                  948616




                  948616




















                      up vote
                      0
                      down vote













                      You can try with below 2 commands also:



                      perl -pne "s/;/:[/" filename
                      sed 's/;/:[/1' filename


                      Output:



                      "100K":["0.00001";"10";"0.01"]
                      "101K":["0.0001";"100";"0.1"]
                      "102K":["1";"1000";"1"]
                      "102K":["1";"1000";"1"]
                      "103K":["0.01";"10000";"10"]
                      "104K":["0.1";"100000";"100"]
                      "105K":["1";"1000000";"1000"]
                      "109K":["0.000001";"1";"1"]
                      "120K":["0.000012";"12";"12"]





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        You can try with below 2 commands also:



                        perl -pne "s/;/:[/" filename
                        sed 's/;/:[/1' filename


                        Output:



                        "100K":["0.00001";"10";"0.01"]
                        "101K":["0.0001";"100";"0.1"]
                        "102K":["1";"1000";"1"]
                        "102K":["1";"1000";"1"]
                        "103K":["0.01";"10000";"10"]
                        "104K":["0.1";"100000";"100"]
                        "105K":["1";"1000000";"1000"]
                        "109K":["0.000001";"1";"1"]
                        "120K":["0.000012";"12";"12"]





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          You can try with below 2 commands also:



                          perl -pne "s/;/:[/" filename
                          sed 's/;/:[/1' filename


                          Output:



                          "100K":["0.00001";"10";"0.01"]
                          "101K":["0.0001";"100";"0.1"]
                          "102K":["1";"1000";"1"]
                          "102K":["1";"1000";"1"]
                          "103K":["0.01";"10000";"10"]
                          "104K":["0.1";"100000";"100"]
                          "105K":["1";"1000000";"1000"]
                          "109K":["0.000001";"1";"1"]
                          "120K":["0.000012";"12";"12"]





                          share|improve this answer














                          You can try with below 2 commands also:



                          perl -pne "s/;/:[/" filename
                          sed 's/;/:[/1' filename


                          Output:



                          "100K":["0.00001";"10";"0.01"]
                          "101K":["0.0001";"100";"0.1"]
                          "102K":["1";"1000";"1"]
                          "102K":["1";"1000";"1"]
                          "103K":["0.01";"10000";"10"]
                          "104K":["0.1";"100000";"100"]
                          "105K":["1";"1000000";"1000"]
                          "109K":["0.000001";"1";"1"]
                          "120K":["0.000012";"12";"12"]






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 5 hours ago









                          David Foerster

                          948616




                          948616










                          answered 7 hours ago









                          Praveen Kumar BS

                          1,030128




                          1,030128



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474287%2freplacing-just-the-first-occurence-of-a-character-in-a-line%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              SBkR4RWyLf,cteGDbF6rFFq7,fiwomj wRsqrRWx9nrCq KxPiHu
                              UCHWs jgZ9VR23 aTRpNjk056pq9S83lOG7FzEebPm

                              Popular posts from this blog

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

                              How many registers does an x86_64 CPU actually have?

                              Displaying single band from multi-band raster using QGIS