Results 1 to 3 of 3

Thread: Escaping double quotes in sed

  1. #1
    Join Date
    Apr 2008
    Location
    England
    Beans
    260
    Distro
    Ubuntu

    Escaping double quotes in sed

    I am trying to replace a line in a file with something stored in a variable using sed but am having some difficulty because both the line I want to replace and the new line contain double quotes. I think that I have found the answer to my question in this stackoverflow thread but I'll be honest, I don't understand the answer given.

    I am trying to replace this:

    Code:
    <transition on="success" to="viewLoginForm" />
    With this:

    Code:
    <transition on="success" to="remoteAuthenticate" />
    At the moment I have the following but it isn't working:

    Code:
    _LOGIN='<transition on="success" to="remoteAuthenticate" />'
    sed -e "/<transition on="success" to="viewLoginForm" \/>/i ${_LOGIN}" /tmp/login-webflow.xml
    I know that my problem stems from the fact that I am using a variable and I can get it working hard coding it and using single quotes but I want to avoid that if possible.

    I would be very grateful if someone could help me to understand the stackoverflow answer or even better, provide me an example of what I am looking to do

    Many thanks!

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Escaping double quotes in sed

    Code:
    $ string='blabla<transition on="success" to="viewLoginForm" />xoxoxo'
    $ login='<transition on="success" to="remoteAuthenticate" />'
    $ echo "$string" | sed 's:<transition on="success" to="viewLoginForm" />:'"$login"':g'
    blabla<transition on="success" to="remoteAuthenticate" />xoxoxo
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Apr 2008
    Location
    England
    Beans
    260
    Distro
    Ubuntu

    Re: Escaping double quotes in sed

    Ah ha, excellent. I think that will work for me.

    Thank you very much for the quick response!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •