M
M
Marat Taganov2021-05-09 22:55:24
linux
Marat Taganov, 2021-05-09 22:55:24

sed command not replacing words?

In theory, the sign should be replaced by , and thus the database should be replenished, but something went wrong

root:~/BOT# bash test.sh
ID: 123456789
[12345678, ${id}, 122345678 ,123453434, 1234534564]
root :~/BOT# cat users.txt
[12345678, 122345678 ,123453434, 1234534564]

root:~/BOT# cat test.sh
read -p "ID: " id
sed -e 's/,/, ${id}, /' users.txt

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2021-05-10
@Lunatik-cyber

Marat Taganov , quotes must be double:
sed -e "s/,/, ${id},/" users.txt
example:

echo a,b,c > users.txt;read -p "ID: " id; sed -e "s/,/, ${id},/" users.txt
ID: 123456
a, 123456,b,c

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question