2

I have this text in this file:

test.php

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'original',
      'username' => 'root',
      'password' => 'root',
      'host' => 'localhost'
    ),
  ),
);

In terminal run this line to replace 'original' with 'new'

sed -i 's/original/new/g' test.php

UPDATE: The error message is:

sed: 1: "test.php": undefined label 'est.php'

What is the problem?

UPDATE 2:

If I just run: ( I removed '-i')

sed 's/original/new/g' test.php

I see the file text modified in the terminal. But then the file is not saved.

10
  • It's rather unlikely to get the error message you've mentioned by issuing sed -i 's/original/new/g' test.php. What command did you use?
    – devnull
    Jan 20, 2014 at 7:33
  • I found that problem is the '-i'. If I run just 'sed 's/original/new/g' test.php' (I removed '-i') it works but the file is not saved.
    – chefnelone
    Jan 20, 2014 at 12:05
  • BTW: why the downvote...?
    – chefnelone
    Jan 20, 2014 at 12:05
  • @devnull I just copy/paste the commands. Pretty sure.
    – chefnelone
    Jan 20, 2014 at 12:06

1 Answer 1

23

On BSDish platforms (including Mac OSX), the -i option requires an argument.

sed -i '' 's/original/new/g' test.php

Notice the empty argument ''.

2

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.