S
S
Sergey Goryachev2016-03-23 23:57:33
linux
Sergey Goryachev, 2016-03-23 23:57:33

How to delete a line containing certain text through the console?

I have a simple BASH that creates hosts for me.

echo "127.0.0.1 $newsite www.$newsite" >> /etc/hosts

Now I'm trying to write a script to delete this line.
sed -i '/$delsite/d' /etc/hosts
Why doesn't it listen to me? Where is the joint?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-03-24
@webirus

sed -i "/$delsite/d" /etc/hosts
but I don't advise you to do this - something will get into the variable and the file will get corrupted completely
make a file with a list of domains and a script to turn the list into a hosts file
to check this type of command, useecho sed -i "/$delsite/d" /etc/hosts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question