Reputation: 3628
I want to run search and replace and I am trying the following command:
sed -i "s/\$enviro ?=.*[^;]/ = 1;/g" constants.php
For some reason when I try and run this is turns into:
sed -i "s/\$enviro\ \?=.\*\[\^\;\]/\ =\ 1\;/g\" constants.php
This then gives errors:
sed: -e expression #1, char 28: unknown option to `s'
I simply want to run the regex \$enviro ?=.*[!;]
and replace it with $enviro = 1;
.
Input - a large config file, one of the lines being:
$enviro = 0;
Output - still large config file:
$enviro = 1;
Upvotes: 1
Views: 37
Reputation: 785761
You can use this sed command:
sed -i.bak 's/\(\$enviro *=\).*/\1 1;/' constants.php
Upvotes: 1
Reputation: 1726
You can try this gnu sed
sed -i -r 's/(\$enviro *= *)[^;]*/\1 1/' file
Upvotes: 1