Remove a line from a file (including newline)
by iicapn from LinuxQuestions.org on (#5DWTY)
Hi,
I'm trying to remove a line from /etc/passwd
Something like this:
sed -i "s|^admin:.*||" /etc/passwd
Which works... but it leaves an unsightly gap in the file. I know sed is probably not the best tool for this, and I've googled and tried all sorts of things with awk, perl, and tr but I can't quite seem to put my finger on it.
Is there an elegant way to remove a line from a text file with regex and include the \n at the end?
Thanks in advance!


I'm trying to remove a line from /etc/passwd
Something like this:
sed -i "s|^admin:.*||" /etc/passwd
Which works... but it leaves an unsightly gap in the file. I know sed is probably not the best tool for this, and I've googled and tried all sorts of things with awk, perl, and tr but I can't quite seem to put my finger on it.
Is there an elegant way to remove a line from a text file with regex and include the \n at the end?
Thanks in advance!