Issue
The name in the title says it all. However, I'm absolutely the worst with the sed command. So I'm trying to edit the following file:
/var/www/html/phpMyAdmin/config.inc.php
I want to edit the line that says
//some text here
$cfg['Servers'][$i]['AllowRoot'] = false;<br />
//some more text here
into the following
//some text here
$cfg['Servers'][$i]['AllowRoot'] = true;<br />
//some more text here
It has so many special characters and whatnot and I have no prior knowledge to how sed works. So here's some commands I've tried to specifically edit that one line.
sed -i "/*.AllowRoot.*/\$cfg['Servers'][\$i]['AllowRoot'] = true;/" /var/www/html/phpMyAdmin/config.inc.php
sed -i "/*.AllowRoot.*/$cfg['Servers'][$i]['AllowRoot'] = true;/" /var/www/html/phpMyAdmin/config.inc.php
<!-- The below finds the line succesfully and prints it so I know it's got the right string -->
sed -n '/AllowRoot/p' /var/www/html/phpMyAdmin/config.inc.php
<!-- End of that line lol -->
sed -i "s/'AllowRoot|false'/'AllowRoot|true'/" /var/www/html/phpMyAdmin/config.inc.php
I have absolutely no idea what I'm doing and I'm not learning a whole lot besides the feeling that the last command splits up 'AllowRoot|false' makes sure that both must be present in the sentence to come back as a result. So to my logic, I thought changing the word "false" into "true" would make that happen, but nothing. The other commands return... bizarre results at best, one even emptying the file. Or that's one of the commands I had not written down here, I've lost track after 50 attempts. What is the solution here?
Kind regards,
Patrick
Solution
The [
and ]
need to be escaped to match literal brackets, instead of inadvertently starting a bracket expression. This should work:
$ sed -i "/\$cfg\['Servers'\]\[\$i\]\['AllowRoot'\]/s/false/true/" /var/www/html/phpMyAdmin/config.inc.php
Answered By - chepner Answer Checked By - Willingham (WPSolving Volunteer)