0

I want to replace the specific string memory_limit = 128M with memory_limit = 512M in the file /etc/php5/apache2/php.ini:

sed 's/memory_limit = 128M/memory_limit = 512M/g'  /etc/php5/apache2/php.ini

Why doesn't the command work?

kos
  • 35,535
  • 13
  • 101
  • 151
showkey
  • 272
  • 4
  • 20
  • 43
  • 4
    Possible duplicate of [Find and replace text within a file using commands](http://askubuntu.com/questions/20414/find-and-replace-text-within-a-file-using-commands) – kos Oct 09 '15 at 11:42
  • 4
    The command works to me. What error are you getting? Note this is going to show the replacement in the screen; if you want to replace in place, say `sed -i.bak ...` so that the original will be replaced and you will also have a safety copy with a .bak extension – fedorqui Oct 09 '15 at 11:47
  • The right format is : – showkey Oct 09 '15 at 12:37
  • sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php5/apache2/php.ini – showkey Oct 09 '15 at 12:37

2 Answers2

3

Just use sed -i to change the file in place.

schlady
  • 46
  • 1
0

You can use Vim in Ex mode:

ex -sc '/memory_limit = /s/128/512/|x' /etc/php5/apache2/php.ini
  1. /memory_limit = / find correct line

  2. s substitute

  3. x save and close

Zombo
  • 1
  • 21
  • 21