0

Im running against the wall in this command..

I want to remove the line:

include "/etc/nginx/software.conf";

from the file called website.

I've tried:

sed -ri '/include \"/etc\/nginx\/wesbite.conf\"\;/d' website

A simple sed command works fine.. but all this special letters confuses me.

Any suggestions please?

Thanks alot.

AdminBee
  • 22,803
  • Welcome to the site. It is not quite clear what you are asking. The command seems to do the job; are you asking for an explanation of the exact syntax? If so, which of the "special letters" are confusing? – AdminBee Oct 05 '20 at 08:45
  • Hi Mate. My own statement doesnt work.

    I need a command that remove: include "/etc/nginx/software.conf";

    from the file "website"

    – Morten Jørgensen Oct 05 '20 at 09:20
  • 1
    I see. The "a simple sed command works fine" seemed to indicate your attempt works. Try it without the backslashes before the double-quotes and the semicolon. Escaping a double-quote is not necessary inside single quotes, and may instead be mis-interpreted. sed '/include "\/etc\/nginx\/software.conf";/d' website should work. Also, there is a typo in the command you presented (wesbite.conf as opposed to software.conf). If that is also in your original command, that may be the problem. – AdminBee Oct 05 '20 at 09:23
  • Hi Thanks alot,

    Sadly it doesnt work. I dont receive any errors.. But the text is still in the file.

    No the typo isnt in the input :D /Morten

    – Morten Jørgensen Oct 05 '20 at 09:28
  • I use:
    sed '/include "/etc/nginx/software.conf";/d' website

    nano website include "/etc/nginx/software.conf";

    – Morten Jørgensen Oct 05 '20 at 09:42
  • Even if the issue is solved, thinking about future readers it would be much better if the command in the question ('/include \"/etc\/nginx\/wesbite.conf\"\;/d') matched the command later shown in a comment ('/include "\/etc\/nginx\/software.conf";/d'). The former doesn't work for the sample input, the latter does (note especially the escaping of the first " and /). – fra-san Oct 10 '20 at 14:18

1 Answers1

0

Fixed by using + instead of / as the delimiter.

sed -i 's+include "/etc/nginx/software.conf";++' website

Thanks for the help.

AdminBee
  • 22,803
  • Congratulations on figuring out a workaround. The only point to remember is that this will erase the line in question by replacing it with an empty line. Effectively this removes it, but there may be cases where that is not desirable. Can you specify what sed version you use? In my test with GNU sed 4.2, the / ... /d approach worked, so it might be version-related. – AdminBee Oct 05 '20 at 13:57