1

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 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .