Find the answer to your Linux question:
Results 1 to 3 of 3
I have a js string bounded by single quotes ('') . That requires that I escape the single quote (') that occurs in "I'm" or "don't". I want " I'm ...
  1. #1
    Just Joined!
    Join Date
    Aug 2010
    Location
    Rochester, NY USA
    Posts
    9

    how to replace ' with \' in sed ?

    I have a js string bounded by single quotes ('') . That requires that I escape the single quote (') that occurs in "I'm" or "don't". I want "I'm" to become "I\'m".

    Fair enough. But this doesn't work: sed -e "s/\'/\'/g"

    The replacement string is unescapable I believe and must be a literal.

    How do I do this in sed ?

  2. #2
    Just Joined! jr0sco's Avatar
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    41
    Code:
    echo "I'm" | sed -e "s/'/\\\'/g"

  3. #3
    Just Joined!
    Join Date
    Aug 2010
    Location
    Rochester, NY USA
    Posts
    9

    Works !

    Your solution works perfectly! Thank you so much! This had befuddled me for half an hour.

    (-Regards, Verlager)

Posting Permissions

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