sed + add word before string only if not existssed + remove char after specific wordAdd text before last matched occurrence of search word in a fileAdd specific word to each linePrint line only if the upper line include specific wordGrep for word stem and print only word (and not line)how to add string if word ended with specific stringsed + mark line in case of marched wordawk + append lines before captured word only if lines are not defined in the fileHow to add properties in the end of the two first lines with double quote?add backslash before specific character

How do I turn off a repeating trade?

Impossible darts scores

How long would it take to cross the Channel in 1890's?

What are the penalties for overstaying in USA?

Find the probability that the 8th woman to appear is in 17th position.

Find the C-factor of a vote

Where can I find a database of galactic spectra?

Suggested order for Amazon Prime Doctor Who series

How to get cool night-vision without lame drawbacks?

Employer wants to use my work email account after I quit

Unusual mail headers, evidence of an attempted attack. Have I been pwned?

How do I respond to requests for a "guarantee" not to leave after a few months?

Is this one of the engines from the 9/11 aircraft?

3D Crossword, Cryptic, Statue View & Maze

Are all instances of trolls turning to stone ultimately references back to Tolkien?

C-152 carb heat on before landing in hot weather?

Is there a way to split the metadata to custom folders?

Should I prioritize my 401(k) over my student loans?

Does Marvel have an equivalent of the Green Lantern?

Hand soldering SMD 1206 components

How to make clear to people I don't want to answer their "Where are you from?" question?

Archery in modern conflicts

Fill NAs in R with zero if the next valid data point is more than 2 intervals away

Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback



sed + add word before string only if not exists


sed + remove char after specific wordAdd text before last matched occurrence of search word in a fileAdd specific word to each linePrint line only if the upper line include specific wordGrep for word stem and print only word (and not line)how to add string if word ended with specific stringsed + mark line in case of marched wordawk + append lines before captured word only if lines are not defined in the fileHow to add properties in the end of the two first lines with double quote?add backslash before specific character






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








2















We have the following line in a file on Linux:



discovery.uri=http://master.navada.com:8800


we want to add the word koko before master, so I just do:



sed –i 's/master/kokomaster/' file


which gives:



discovery.uri=http://kokomaster.navada.com:8800


but what we want is to add koko only if koko isn't already present before master.



For example, the next time that we run



sed –i 's/master/kokomaster/' file


the line will be:



discovery.uri=http://kokokokomaster.navada.com:8800









share|improve this question






























    2















    We have the following line in a file on Linux:



    discovery.uri=http://master.navada.com:8800


    we want to add the word koko before master, so I just do:



    sed –i 's/master/kokomaster/' file


    which gives:



    discovery.uri=http://kokomaster.navada.com:8800


    but what we want is to add koko only if koko isn't already present before master.



    For example, the next time that we run



    sed –i 's/master/kokomaster/' file


    the line will be:



    discovery.uri=http://kokokokomaster.navada.com:8800









    share|improve this question


























      2












      2








      2








      We have the following line in a file on Linux:



      discovery.uri=http://master.navada.com:8800


      we want to add the word koko before master, so I just do:



      sed –i 's/master/kokomaster/' file


      which gives:



      discovery.uri=http://kokomaster.navada.com:8800


      but what we want is to add koko only if koko isn't already present before master.



      For example, the next time that we run



      sed –i 's/master/kokomaster/' file


      the line will be:



      discovery.uri=http://kokokokomaster.navada.com:8800









      share|improve this question
















      We have the following line in a file on Linux:



      discovery.uri=http://master.navada.com:8800


      we want to add the word koko before master, so I just do:



      sed –i 's/master/kokomaster/' file


      which gives:



      discovery.uri=http://kokomaster.navada.com:8800


      but what we want is to add koko only if koko isn't already present before master.



      For example, the next time that we run



      sed –i 's/master/kokomaster/' file


      the line will be:



      discovery.uri=http://kokokokomaster.navada.com:8800






      text-processing sed configuration






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 6 at 13:27









      terdon

      137k33 gold badges283 silver badges459 bronze badges




      137k33 gold badges283 silver badges459 bronze badges










      asked Jun 6 at 12:12









      yaelyael

      2,9028 gold badges39 silver badges87 bronze badges




      2,9028 gold badges39 silver badges87 bronze badges




















          5 Answers
          5






          active

          oldest

          votes


















          4














          You can replace a bit more to avoid this problem:



          sed -i sX/masterX/kokomasterX file


          This replaces “/master”, so the next time you run it, nothing will be replaced, since “/kokomaster” doesn’t match.






          share|improve this answer






























            4














            sed -i '/kokomaster/!s/master/koko&/' file


            First test whether the string kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the koko word only if koko not exists before master word" into sed.



            The & in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e. master).




            After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any master string elsewhere, even if kokomaster occurred (or not) in the URI path:



            sed -i 's,^(discovery.uri=http://)(master),1koko2,' file


            You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:



            sed -i 's,^(discovery.uri=http://)(master.navada.com:8800)$,1koko2,' file


            If the configuration file is written in JSON or some other well know format, you would not use sed at all, but jq or some other apropriate tool specifically written for handling files of that format.






            share|improve this answer




















            • 1





              That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

              – Stéphane Chazelas
              Jun 6 at 13:54











            • @StéphaneChazelas Correct, as per the explicit specification from the user.

              – Kusalananda
              Jun 6 at 14:51












            • Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

              – Stéphane Chazelas
              Jun 6 at 14:54











            • @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

              – Kusalananda
              Jun 6 at 15:35











            • @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

              – Philippos
              Jun 6 at 16:32


















            3














            Use



            sed 's/(koko)*master/kokomaster/'


            so master and any number of preceeding kokos get replaced.






            share|improve this answer























            • Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

              – Stéphane Chazelas
              Jun 6 at 13:52


















            2














            If you're open to other tools:



            perl -i -pe 's/(?<!koko)master/kokomaster/' file


            The (?>!foo) is a negative lookbehind, so (?<!koko)master will only match master when not preceded by koko.






            share|improve this answer
































              2














              I have used below awk command to do the same



              command



              awk '$0 !~/kokomaster/gsub("master","kokomaster",$0)1' filename >file_tmp && mv file_tmp filename


              output



              discovery.uri=http://kokomaster.navada.com:8800
              discovery.uri=http://kokomaster.navada.com:8800





              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',
                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%2f523302%2fsed-add-word-before-string-only-if-not-exists%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                You can replace a bit more to avoid this problem:



                sed -i sX/masterX/kokomasterX file


                This replaces “/master”, so the next time you run it, nothing will be replaced, since “/kokomaster” doesn’t match.






                share|improve this answer



























                  4














                  You can replace a bit more to avoid this problem:



                  sed -i sX/masterX/kokomasterX file


                  This replaces “/master”, so the next time you run it, nothing will be replaced, since “/kokomaster” doesn’t match.






                  share|improve this answer

























                    4












                    4








                    4







                    You can replace a bit more to avoid this problem:



                    sed -i sX/masterX/kokomasterX file


                    This replaces “/master”, so the next time you run it, nothing will be replaced, since “/kokomaster” doesn’t match.






                    share|improve this answer













                    You can replace a bit more to avoid this problem:



                    sed -i sX/masterX/kokomasterX file


                    This replaces “/master”, so the next time you run it, nothing will be replaced, since “/kokomaster” doesn’t match.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 6 at 12:15









                    Stephen KittStephen Kitt

                    191k26 gold badges457 silver badges528 bronze badges




                    191k26 gold badges457 silver badges528 bronze badges























                        4














                        sed -i '/kokomaster/!s/master/koko&/' file


                        First test whether the string kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the koko word only if koko not exists before master word" into sed.



                        The & in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e. master).




                        After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any master string elsewhere, even if kokomaster occurred (or not) in the URI path:



                        sed -i 's,^(discovery.uri=http://)(master),1koko2,' file


                        You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:



                        sed -i 's,^(discovery.uri=http://)(master.navada.com:8800)$,1koko2,' file


                        If the configuration file is written in JSON or some other well know format, you would not use sed at all, but jq or some other apropriate tool specifically written for handling files of that format.






                        share|improve this answer




















                        • 1





                          That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                          – Stéphane Chazelas
                          Jun 6 at 13:54











                        • @StéphaneChazelas Correct, as per the explicit specification from the user.

                          – Kusalananda
                          Jun 6 at 14:51












                        • Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                          – Stéphane Chazelas
                          Jun 6 at 14:54











                        • @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                          – Kusalananda
                          Jun 6 at 15:35











                        • @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                          – Philippos
                          Jun 6 at 16:32















                        4














                        sed -i '/kokomaster/!s/master/koko&/' file


                        First test whether the string kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the koko word only if koko not exists before master word" into sed.



                        The & in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e. master).




                        After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any master string elsewhere, even if kokomaster occurred (or not) in the URI path:



                        sed -i 's,^(discovery.uri=http://)(master),1koko2,' file


                        You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:



                        sed -i 's,^(discovery.uri=http://)(master.navada.com:8800)$,1koko2,' file


                        If the configuration file is written in JSON or some other well know format, you would not use sed at all, but jq or some other apropriate tool specifically written for handling files of that format.






                        share|improve this answer




















                        • 1





                          That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                          – Stéphane Chazelas
                          Jun 6 at 13:54











                        • @StéphaneChazelas Correct, as per the explicit specification from the user.

                          – Kusalananda
                          Jun 6 at 14:51












                        • Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                          – Stéphane Chazelas
                          Jun 6 at 14:54











                        • @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                          – Kusalananda
                          Jun 6 at 15:35











                        • @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                          – Philippos
                          Jun 6 at 16:32













                        4












                        4








                        4







                        sed -i '/kokomaster/!s/master/koko&/' file


                        First test whether the string kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the koko word only if koko not exists before master word" into sed.



                        The & in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e. master).




                        After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any master string elsewhere, even if kokomaster occurred (or not) in the URI path:



                        sed -i 's,^(discovery.uri=http://)(master),1koko2,' file


                        You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:



                        sed -i 's,^(discovery.uri=http://)(master.navada.com:8800)$,1koko2,' file


                        If the configuration file is written in JSON or some other well know format, you would not use sed at all, but jq or some other apropriate tool specifically written for handling files of that format.






                        share|improve this answer















                        sed -i '/kokomaster/!s/master/koko&/' file


                        First test whether the string kokomaster exists on the line, and if it doesn't, do the substitution. This is almost a literal translation of "but what we want is to add the koko word only if koko not exists before master word" into sed.



                        The & in the replacement part of the substitution will be replaced by the text matched by the pattern part (i.e. master).




                        After reading the comments (see below), you may want to use something more specific that would actually only modify the server name portion of the URI, and not any master string elsewhere, even if kokomaster occurred (or not) in the URI path:



                        sed -i 's,^(discovery.uri=http://)(master),1koko2,' file


                        You may even want to go as far as matching the exact and full line that you'd want to replace, just to avoid even hypothetical mistakes:



                        sed -i 's,^(discovery.uri=http://)(master.navada.com:8800)$,1koko2,' file


                        If the configuration file is written in JSON or some other well know format, you would not use sed at all, but jq or some other apropriate tool specifically written for handling files of that format.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jun 6 at 16:50

























                        answered Jun 6 at 12:52









                        KusalanandaKusalananda

                        152k18 gold badges298 silver badges478 bronze badges




                        152k18 gold badges298 silver badges478 bronze badges







                        • 1





                          That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                          – Stéphane Chazelas
                          Jun 6 at 13:54











                        • @StéphaneChazelas Correct, as per the explicit specification from the user.

                          – Kusalananda
                          Jun 6 at 14:51












                        • Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                          – Stéphane Chazelas
                          Jun 6 at 14:54











                        • @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                          – Kusalananda
                          Jun 6 at 15:35











                        • @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                          – Philippos
                          Jun 6 at 16:32












                        • 1





                          That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                          – Stéphane Chazelas
                          Jun 6 at 13:54











                        • @StéphaneChazelas Correct, as per the explicit specification from the user.

                          – Kusalananda
                          Jun 6 at 14:51












                        • Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                          – Stéphane Chazelas
                          Jun 6 at 14:54











                        • @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                          – Kusalananda
                          Jun 6 at 15:35











                        • @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                          – Philippos
                          Jun 6 at 16:32







                        1




                        1





                        That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                        – Stéphane Chazelas
                        Jun 6 at 13:54





                        That wouldn't work on discovery.uri=http://master.navada.com:8800/kokomaster though.

                        – Stéphane Chazelas
                        Jun 6 at 13:54













                        @StéphaneChazelas Correct, as per the explicit specification from the user.

                        – Kusalananda
                        Jun 6 at 14:51






                        @StéphaneChazelas Correct, as per the explicit specification from the user.

                        – Kusalananda
                        Jun 6 at 14:51














                        Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                        – Stéphane Chazelas
                        Jun 6 at 14:54





                        Not sure I follow. In discovery.uri=http://master.navada.com:8800/kokomaster, there's no koko before the first master. Yet, that sed line doesn't add one.

                        – Stéphane Chazelas
                        Jun 6 at 14:54













                        @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                        – Kusalananda
                        Jun 6 at 15:35





                        @StéphaneChazelas Sorry, that was half a joke, but it is actually what the user specified. If the string koko does not already occur before master, it should not be added again. That's what's requested, and that's what I did, pedantically following the request to the letter. In your string, koko already occurs right before master, so it's not added again.

                        – Kusalananda
                        Jun 6 at 15:35













                        @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                        – Philippos
                        Jun 6 at 16:32





                        @Kusalananda nope. The master in the server name needs to be replaced even if there may be some kokomaster in the path. Pedanticly. I guess the OP doesn't care.

                        – Philippos
                        Jun 6 at 16:32











                        3














                        Use



                        sed 's/(koko)*master/kokomaster/'


                        so master and any number of preceeding kokos get replaced.






                        share|improve this answer























                        • Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                          – Stéphane Chazelas
                          Jun 6 at 13:52















                        3














                        Use



                        sed 's/(koko)*master/kokomaster/'


                        so master and any number of preceeding kokos get replaced.






                        share|improve this answer























                        • Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                          – Stéphane Chazelas
                          Jun 6 at 13:52













                        3












                        3








                        3







                        Use



                        sed 's/(koko)*master/kokomaster/'


                        so master and any number of preceeding kokos get replaced.






                        share|improve this answer













                        Use



                        sed 's/(koko)*master/kokomaster/'


                        so master and any number of preceeding kokos get replaced.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jun 6 at 12:46









                        PhilipposPhilippos

                        6,5961 gold badge19 silver badges51 bronze badges




                        6,5961 gold badge19 silver badges51 bronze badges












                        • Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                          – Stéphane Chazelas
                          Jun 6 at 13:52

















                        • Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                          – Stéphane Chazelas
                          Jun 6 at 13:52
















                        Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                        – Stéphane Chazelas
                        Jun 6 at 13:52





                        Or better, sed 's/(koko)0,1master/kokomaster/' to avoid replacing kokokokomaster with kokomaster.

                        – Stéphane Chazelas
                        Jun 6 at 13:52











                        2














                        If you're open to other tools:



                        perl -i -pe 's/(?<!koko)master/kokomaster/' file


                        The (?>!foo) is a negative lookbehind, so (?<!koko)master will only match master when not preceded by koko.






                        share|improve this answer





























                          2














                          If you're open to other tools:



                          perl -i -pe 's/(?<!koko)master/kokomaster/' file


                          The (?>!foo) is a negative lookbehind, so (?<!koko)master will only match master when not preceded by koko.






                          share|improve this answer



























                            2












                            2








                            2







                            If you're open to other tools:



                            perl -i -pe 's/(?<!koko)master/kokomaster/' file


                            The (?>!foo) is a negative lookbehind, so (?<!koko)master will only match master when not preceded by koko.






                            share|improve this answer















                            If you're open to other tools:



                            perl -i -pe 's/(?<!koko)master/kokomaster/' file


                            The (?>!foo) is a negative lookbehind, so (?<!koko)master will only match master when not preceded by koko.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jun 6 at 14:56

























                            answered Jun 6 at 13:32









                            terdonterdon

                            137k33 gold badges283 silver badges459 bronze badges




                            137k33 gold badges283 silver badges459 bronze badges





















                                2














                                I have used below awk command to do the same



                                command



                                awk '$0 !~/kokomaster/gsub("master","kokomaster",$0)1' filename >file_tmp && mv file_tmp filename


                                output



                                discovery.uri=http://kokomaster.navada.com:8800
                                discovery.uri=http://kokomaster.navada.com:8800





                                share|improve this answer



























                                  2














                                  I have used below awk command to do the same



                                  command



                                  awk '$0 !~/kokomaster/gsub("master","kokomaster",$0)1' filename >file_tmp && mv file_tmp filename


                                  output



                                  discovery.uri=http://kokomaster.navada.com:8800
                                  discovery.uri=http://kokomaster.navada.com:8800





                                  share|improve this answer

























                                    2












                                    2








                                    2







                                    I have used below awk command to do the same



                                    command



                                    awk '$0 !~/kokomaster/gsub("master","kokomaster",$0)1' filename >file_tmp && mv file_tmp filename


                                    output



                                    discovery.uri=http://kokomaster.navada.com:8800
                                    discovery.uri=http://kokomaster.navada.com:8800





                                    share|improve this answer













                                    I have used below awk command to do the same



                                    command



                                    awk '$0 !~/kokomaster/gsub("master","kokomaster",$0)1' filename >file_tmp && mv file_tmp filename


                                    output



                                    discovery.uri=http://kokomaster.navada.com:8800
                                    discovery.uri=http://kokomaster.navada.com:8800






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jun 6 at 15:20









                                    Praveen Kumar BSPraveen Kumar BS

                                    2,1302 gold badges3 silver badges11 bronze badges




                                    2,1302 gold badges3 silver badges11 bronze badges



























                                        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%2f523302%2fsed-add-word-before-string-only-if-not-exists%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

                                        Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                                        Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                                        What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company