Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top