Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to delete one or more specific line numbers from a file. How would I do this using sed?

share|improve this question
up vote 24 down vote accepted

To delete lines 2, 12-17 and line 57 from file data.txt using sed you could do something like this:

 sed -e '2d;12,17d;57d' data.txt

to create a backup of the original file (with a .bak extension) use -i.bak with the command.

 sed -i.bak -e '2d;12,17d;57d' data.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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