Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Remove specified lines from a file using sed

Answer:

Assume your have a file text.txt contains 100 lines, if you want to remove the lines 20-30, what you need is sed:

# sed '20,30d' text.txt

That's is easy.

  1. Remove comments (#) and empty lines in a file
  2. Delete all trailing blank lines at end of file using sed
  3. How to remove duplicated lines in a file
  4. Remove empty lines in a file
  5. How to easy remove file with strange file name?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>