NobleUplift
NobleUplift

Reputation: 6024

sed treating filename as pattern?

I have the following sed command to comment out phpinfo() from my index.php:

sudo sed -i "s/phpinfo();/\/\/phpinfo();/g" index.php

But it gives me:

$ sudo sed -i "s/phpinfo();/\/\/phpinfo();/g" index.php
sed: 1: "index.php": command i expects \ followed by text

If I try to specify the entire path, it does the same thing:

sed: 1: "/Library/WebServer/Docu ...": invalid command code W

What am I doing wrong?

Upvotes: 2

Views: 291

Answers (1)

anubhava
anubhava

Reputation: 785256

Try this sed:

sudo sed -i.bak "s~phpinfo();~//phpinfo();~g" index.php
  • Older sed versions need file extension with -i flag
  • Better to use an alternative regex delimiter to avoid escaping /

Upvotes: 2

Related Questions