2

This question already has an answer here:

I'm trying to edit a file on a remote server via a terminal and to make a change in said file I have to (or have used so far) use the 'sed' command.

in the below file i want to delete the string STUFF_456 and its new line character.

STUFF_123
STUFF_456
STUFF_789

However when I use this command in sed i'm left with a blank line.

$ sed -i 's/STUFF_456//' /file/path/here.txt
STUFF_123

STUFF_789

I need to get rid of the blank line and keep the other two entries.

How can I accomplish this?

marked as duplicate by Sergiy Kolodyazhnyy bash Oct 23 '18 at 23:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You can delete the line with:

sed '/^STUFF_456$/d'

This deletes every line being STUFF_456, ^ marks the beginning of the line and $ marks the end.

With your example:

$ sed '/^STUFF_456$/d' /file/path/here.txt
STUFF_123
STUFF_789

Not the answer you're looking for? Browse other questions tagged or ask your own question.