Searching for an entry and deleting the line

Hi

Im trying to scan a file for certain entries and remove their corresponding lines completely. What I have now is this,

for USER in user1 user2 user3 user4
do
sed '/$USER/d' /etc/sudoers
done

However this doesn't remove the entries at all. Is there another way for this?

Thanks very much

---------- Post updated at 09:11 PM ---------- Previous update was at 09:08 PM ----------

Edit: I think the $ sign gives the wrong info to sed. Should this be enclosed in something?

the single-quotations don't allow for expansion. but then you also need in-place editing:

sed -i "/$USER/d" /etc/sudoers

or better

sed -i.bak

so that it saves the backup

1 Like

This worked. Thank you!