0

say I am given this file

username1
username2
username3

I want to delete a line that contains something I say. Like for example:

$ deletestuff abovefile username2
$ cat file
username1
username3
1

Use sed -i to edit in place. /regexp/d deletes lines matching regexp.

sed -i /username2/d file

To match whole lines (so that, for example, username222 is not also removed) use ^ and $ to anchor the search to start and end of the line.

sed -i '/^username2$/d' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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