Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3855134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:43:45+00:00 2026-05-19T17:43:45+00:00

Having some difficulty in replacing some single/double quoted text with sed and was wondering

  • 0

Having some difficulty in replacing some single/double quoted text with sed and was wondering what’s the correct method for these 2 examples

to change Memached.ini file contents from

[server]
server[] = "localhost:11211"

to

[server]
server[] = "localhost:11211"
server[] = "localhost:11212"

and to change memcache.php file contents for these lines from

define('ADMIN_USERNAME','username');    // Admin Username
define('ADMIN_PASSWORD','password');    // Admin Password

$MEMCACHE_SERVERS[] = 'mymemcache-server1:11211'; // add more as an array
$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array

to

define('ADMIN_USERNAME','myusername');  // Admin Username
define('ADMIN_PASSWORD','mypassword');      // Admin Password

$MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array
$MEMCACHE_SERVERS[] = 'localhost:11212'; // add more as an array

I tried for example

sed -i 's/'ADMIN_USERNAME','memcache'/'ADMIN_USERNAME','u'/g' /var/www/html/memcache.php

while command runs, memcache.php file isn’t changed at all ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:43:46+00:00Added an answer on May 19, 2026 at 5:43 pm

    You can replace the single quotes in the sed command with double-quoted single quotes. The shell sees a single quote as ending a string. So, let it. You had

    sed -i 's/'ADMIN_USERNAME','memcache'/'ADMIN_USERNAME','u'/g' /var/www/html/memcache.php
    

    But, if you replace the ‘ in the sed command with ‘”‘”‘, then shell will see the first ‘ as ending the first single-quoted string, then “‘” as a double-quoted single quote, and then the last ‘ as a beginning of a new single-quoted string. That’d be

    sed -i 's/'"'"'ADMIN_USERNAME'"'"','"'"'memcache'"'"'/'"'"'ADMIN_USERNAME'"'"','"'"'u'"'"'/g' /var/www/html/memcache.php
    

    You should also be able to do ‘\” in place of the ‘ within the command, for the same reason.

    sed -i 's/'\''ADMIN_USERNAME\'',\''memcache\''/\''ADMIN_USERNAME\'',\''u\''/g' /var/www/html/memcache.php
    

    But really, it’d be better to use an alternative mechanism. I’d suggest defining the source and target strings as variables, and then put those in the sed string.

    SRC="'ADMIN_USERNAME','memcache'"
    DST="'ADMIN_USERNAME','u'"
    sed -i "s/$SRC/$DST/g" /var/www/html/memcache.php
    

    That’s way more readable, and it makes it easier for you to handle the quoting mess in a sane way with bite-sized chunks. Yay “shell variable contents aren’t subject to word expansion unless you force it” knowledge. 🙂

    Make sure you don’t put a / in the $SRC or $DST variables, though. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some difficulty understanding a certain aspect of the @async annotation, and possibly
I'm having some difficulty cloning my mercurial repository over ssh. Here's what I have
I'm having some difficulty wrapping my head around building an OGC compliant Earth Observation
I'm having some some difficulty predicting how my C code will truncate results. Refer
I am having some difficulty with sessions. On my local MAMP test server, if
I'm having some difficulty including a directory into the jar maven is creating. I
I am having some difficulty with an Android layout problem. I am trying to
I have following code: SELECT q21, q21coding AS Description FROM `tresults_acme` WHERE q21 IS
I have come across an awkward situation where I would like to have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.