0

I want to add a string in particular place in a paragraph

that is:

$rcmail_config['default_host'] = '';

to

$rcmail_config['default_host'] = 'abcdef';

Is it possible using sed?

2 Answers 2

1

Make:

sed -i "s/\$rcmail_config\['default_host'\] =.*/\$rcmail_config['default_host'] = 'abcdef';/" /your.file

It will replace only the line, and set your data regardless of what previously.

Sign up to request clarification or add additional context in comments.

1 Comment

use group to simplify the replace pattern (avoid error and more easy to read)
1

sed -e "/\$rcmail_config/s/'';$/'abcdef';/" should do what you want.

> echo -e "foo = '';\nbar = '';\n\$rcmail_config['default_host'] = '';"
foo = '';
bar = '';
$rcmail_config['default_host'] = '';

> echo -e "foo = '';\nbar = '';\n\$rcmail_config['default_host'] = '';" | sed -e "/\$rcmail_config/s/'';$/'abcdef';/"
foo = '';
bar = '';
$rcmail_config['default_host'] = 'abcdef';

2 Comments

assuming there is only one $rcmail_config in the file (certainly the case)
Granted. More but I can't restrict more given what the OP wrote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.