skip to Main Content

I have been reading through the various sed issues and have one I cannot get to work:

I want to replace:

define('CIVICRM_LOGGING_DSN', CIVICRM_DSN);

With

define('CIVICRM_LOGGING_DSN', myuser:mypassword@localhost:3306civicrm_uat_logs);

This almost works…

sed -i -e "s/define('CIVICRM_LOGGING_DSN', CIVICRM_DSN);/define('CIVICRM_LOGGING_DSN', 'myuser:mypassword@localhost:3306civicrm_uat_logs');/" /my_path/civicrm.settings.php

The output is:

define('CIVICRM_LOGGING_DSN', myuser:mypassword@localhost:3306  vicrm_uat_logs);

The issue is I get is that missing ‘ci’. This, I assume is due to the backslash, but why two chars?! If I had ‘my_database’ instead of civicrm_uat_logs , I’d just lose the backslash.

I cannot seem to escape the backslash no matter, but maybe something else is going on?

Struggling with this one, but it must be simple…

I’m on Ubuntu 22.04 LTS

UPDATE:

I realsed that I needed quotes around the database string… so the replacement should be:

define('CIVICRM_LOGGING_DSN', 'myuser:mypassword@localhost:3306civicrm_uat_logs');

Now,nothing get’s replaced but no error…

2

Answers


  1. Chosen as BEST ANSWER

    OK, with the help of a kind and knowledgeable friend. The shell and sed are nested so:

    sed -i -e "s/define('CIVICRM_LOGGING_DSN', CIVICRM_DSN);/define('CIVICRM_LOGGING_DSN', 'civicrm:civicrm@db:3306\\civicrm_uat_logs');/"
    

    Escaping both the backslash and the 'c'


  2. Using sed

    $ sed -E "s/([^,]*, ).*/1myuser:mypassword@localhost:3306\civicrm_uat_logs);/" input_file
    define('CIVICRM_LOGGING_DSN', myuser:mypassword@localhost:3306civicrm_uat_logs);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search