- This topic has 2 replies, 2 voices, and was last updated 3 years ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
› Forums › Basic skills › Programming › Shell scripting (in bash) › Deleting users from info.txt
How can I delete the entire row that contains a user that I have identified as “bad”?
My code is in the attachment.
I have a file that contains only the names/uun of users that I have identified as bad.
For each user:
– if they are still in info.txt
then remove the entire row where the string matches
Currently it only deletes the string itself, nothing else.
From what I can find in shell scripting forums the command I used should delete the entire line which contains the substring specified in $USER for all instances in info.txt (globally).
What am I not seeing? I tried converting info.txt into a csv, but it seems even more complicated to delete an entire row in csv. I have replaced the tabs in info.txt with spaces, in case it doesn’t recognise the lines as rows because of the tabs. Nothing works.
Any help appreciated!
You need to expand the sed command to match the entire line, eg. ^$USER .*$
($
here means the end of the line, ^
mean the beginning of the line). But there’s also a tricky thing with sed and newlines, so since you want to delete the whole line, you can use the d
flag, i.e. delete:
sed -i '/^$USER .*$/d' info.txt
This assumes that it’s just spaces separating the columns.
There are some more examples and explanation of the flags (probably too much info) here:
https://www.gnu.org/software/sed/manual/sed.html
cheers,
Catherine
Thank you! This solved the problem of deleting the entire line from info.txt
Some forums are only available if you are logged in. Searching will only return results from those forums if you log in.
Copyright © 2024 · Balance Child Theme on Genesis Framework · WordPress · Log in