Use of sed with double quotation

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











up vote
2
down vote

favorite












Answering to this question:



I found the following situation with sed version 4.2.2.



From this input:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search, host-name,
# option host-name "andare.swiftmedia.com";


I want to remove the string "host-name" only from the second line, so the expected output is:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search,
# option host-name "andare.swiftmedia.com";


Then I used the following command:



sed -e 's/" host-name,"//g' input_file


However, it won't remove the " host-name," string on input_file leaving it as it was.



If I don't use double quotation:



sed -e 's/ host-name,//g' input_file


It gives properly the expected output.



I thought that the correct way would be by using double quotation, but can't figure out why it's not working here.







share|improve this question


















  • 1




    see also mywiki.wooledge.org/Quotes
    – Sundeep
    Nov 28 '17 at 13:19














up vote
2
down vote

favorite












Answering to this question:



I found the following situation with sed version 4.2.2.



From this input:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search, host-name,
# option host-name "andare.swiftmedia.com";


I want to remove the string "host-name" only from the second line, so the expected output is:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search,
# option host-name "andare.swiftmedia.com";


Then I used the following command:



sed -e 's/" host-name,"//g' input_file


However, it won't remove the " host-name," string on input_file leaving it as it was.



If I don't use double quotation:



sed -e 's/ host-name,//g' input_file


It gives properly the expected output.



I thought that the correct way would be by using double quotation, but can't figure out why it's not working here.







share|improve this question


















  • 1




    see also mywiki.wooledge.org/Quotes
    – Sundeep
    Nov 28 '17 at 13:19












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Answering to this question:



I found the following situation with sed version 4.2.2.



From this input:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search, host-name,
# option host-name "andare.swiftmedia.com";


I want to remove the string "host-name" only from the second line, so the expected output is:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search,
# option host-name "andare.swiftmedia.com";


Then I used the following command:



sed -e 's/" host-name,"//g' input_file


However, it won't remove the " host-name," string on input_file leaving it as it was.



If I don't use double quotation:



sed -e 's/ host-name,//g' input_file


It gives properly the expected output.



I thought that the correct way would be by using double quotation, but can't figure out why it's not working here.







share|improve this question














Answering to this question:



I found the following situation with sed version 4.2.2.



From this input:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search, host-name,
# option host-name "andare.swiftmedia.com";


I want to remove the string "host-name" only from the second line, so the expected output is:



send host-name = gethostname();
domain-name, domain-name-servers, domain-search,
# option host-name "andare.swiftmedia.com";


Then I used the following command:



sed -e 's/" host-name,"//g' input_file


However, it won't remove the " host-name," string on input_file leaving it as it was.



If I don't use double quotation:



sed -e 's/ host-name,//g' input_file


It gives properly the expected output.



I thought that the correct way would be by using double quotation, but can't figure out why it's not working here.









share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '17 at 11:38

























asked Nov 28 '17 at 11:34









Zumo de Vidrio

1,277318




1,277318







  • 1




    see also mywiki.wooledge.org/Quotes
    – Sundeep
    Nov 28 '17 at 13:19












  • 1




    see also mywiki.wooledge.org/Quotes
    – Sundeep
    Nov 28 '17 at 13:19







1




1




see also mywiki.wooledge.org/Quotes
– Sundeep
Nov 28 '17 at 13:19




see also mywiki.wooledge.org/Quotes
– Sundeep
Nov 28 '17 at 13:19










1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










The character " is not special for the shell inside '...'. In fact, inside '...' no character is special for the shell; as a consequence, the " characters are passed to sed; and they are not special to sed.



The command sed -e 's/" host-name,"//g' is looking literally for "   h o s t n a m e , ", which it won't find because it's not there.






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%2f407479%2fuse-of-sed-with-double-quotation%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    6
    down vote



    accepted










    The character " is not special for the shell inside '...'. In fact, inside '...' no character is special for the shell; as a consequence, the " characters are passed to sed; and they are not special to sed.



    The command sed -e 's/" host-name,"//g' is looking literally for "   h o s t n a m e , ", which it won't find because it's not there.






    share|improve this answer
























      up vote
      6
      down vote



      accepted










      The character " is not special for the shell inside '...'. In fact, inside '...' no character is special for the shell; as a consequence, the " characters are passed to sed; and they are not special to sed.



      The command sed -e 's/" host-name,"//g' is looking literally for "   h o s t n a m e , ", which it won't find because it's not there.






      share|improve this answer






















        up vote
        6
        down vote



        accepted







        up vote
        6
        down vote



        accepted






        The character " is not special for the shell inside '...'. In fact, inside '...' no character is special for the shell; as a consequence, the " characters are passed to sed; and they are not special to sed.



        The command sed -e 's/" host-name,"//g' is looking literally for "   h o s t n a m e , ", which it won't find because it's not there.






        share|improve this answer












        The character " is not special for the shell inside '...'. In fact, inside '...' no character is special for the shell; as a consequence, the " characters are passed to sed; and they are not special to sed.



        The command sed -e 's/" host-name,"//g' is looking literally for "   h o s t n a m e , ", which it won't find because it's not there.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '17 at 11:43









        AlexP

        6,656924




        6,656924



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407479%2fuse-of-sed-with-double-quotation%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay