I
I
Igor Petrov2020-11-25 20:18:21
linux
Igor Petrov, 2020-11-25 20:18:21

How to delete lines containing words in bash?

Good day!
Please tell me how to delete a line containing a specific name, it is with a dot, through this script, it runs without errors, but the line is not deleted, and if executed directly from the console with the command sed -i 'domain.ru/d' /etc/pool/conf .py, then the line is deleted, it is necessary to delete the lines through the bash script

#!/bin/bash
echo "Enter domain":
read domain
sed -i '$domain/d' /etc/pool/conf.py

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Vasilyev, 2020-11-25
@daniks

$ cat test.sh 
#!/bin/bash
echo "Enter domain":
read domain
sed -i "/$domain/d" test.txt

Result:
cat test.txt 
aaa.com
bbb.com
ccc.com

 ./test.sh 
Enter domain:
bbb.com

cat test.txt 
aaa.com
ccc.com

A
AVKor, 2020-11-25
@AVKor

$ a="test";echo "$a";echo '$a'
test
$a

A small test showing what the error is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question