Search and replace a pattern containing backslashes

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








up vote
2
down vote

favorite












I have a file



bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


I need to search for newcommanddatestamp and want to replace a nearby pattern with a new pattern.



Required output file



bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


The backslashes are complicating this task. How do I manage?










share|improve this question



















  • 4




    the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
    – Zanna
    Mar 11 at 16:19















up vote
2
down vote

favorite












I have a file



bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


I need to search for newcommanddatestamp and want to replace a nearby pattern with a new pattern.



Required output file



bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


The backslashes are complicating this task. How do I manage?










share|improve this question



















  • 4




    the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
    – Zanna
    Mar 11 at 16:19













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a file



bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


I need to search for newcommanddatestamp and want to replace a nearby pattern with a new pattern.



Required output file



bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


The backslashes are complicating this task. How do I manage?










share|improve this question















I have a file



bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


I need to search for newcommanddatestamp and want to replace a nearby pattern with a new pattern.



Required output file



bla bla bla bla bla bla bla 
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla


The backslashes are complicating this task. How do I manage?







command-line text-processing latex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 11 at 19:34









David Foerster

26.4k1362106




26.4k1362106










asked Mar 9 at 14:33









user3708021

232




232







  • 4




    the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
    – Zanna
    Mar 11 at 16:19













  • 4




    the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
    – Zanna
    Mar 11 at 16:19








4




4




the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
– Zanna
Mar 11 at 16:19





the dupe target doesn't make sense. sed is not a shell and the backslashes are not in filenames
– Zanna
Mar 11 at 16:19











1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










You likely just need to escape the backslashes i.e. \



Ex.



$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1013419%2fsearch-and-replace-a-pattern-containing-backslashes%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










    You likely just need to escape the backslashes i.e. \



    Ex.



    $ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
    bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla
    newcommanddatestamp20180218
    bla bla bla bla bla bla bla
    bla bla bla bla bla bla bla





    share|improve this answer
























      up vote
      6
      down vote



      accepted










      You likely just need to escape the backslashes i.e. \



      Ex.



      $ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
      bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla
      newcommanddatestamp20180218
      bla bla bla bla bla bla bla
      bla bla bla bla bla bla bla





      share|improve this answer






















        up vote
        6
        down vote



        accepted







        up vote
        6
        down vote



        accepted






        You likely just need to escape the backslashes i.e. \



        Ex.



        $ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
        bla bla bla bla bla bla bla
        bla bla bla bla bla bla bla
        newcommanddatestamp20180218
        bla bla bla bla bla bla bla
        bla bla bla bla bla bla bla





        share|improve this answer












        You likely just need to escape the backslashes i.e. \



        Ex.



        $ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
        bla bla bla bla bla bla bla
        bla bla bla bla bla bla bla
        newcommanddatestamp20180218
        bla bla bla bla bla bla bla
        bla bla bla bla bla bla bla






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 14:36









        steeldriver

        63.2k1198167




        63.2k1198167



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013419%2fsearch-and-replace-a-pattern-containing-backslashes%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491