This question already has an answer here:

I have a text file which has about 70000000 lines in Linux system.

How to delete the lines from 40000000 to 50000000 without opening the file?


marked as duplicate by EightBitTony, chaos, garethTheRed, Wouter Verhelst, DopeGhoti Mar 1 '16 at 7:53

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.

  • 2
    I don't think the concept opening a file is now used properly. In order to make any changes to a file, you'd have to call open(2) before doing anything else. – Sami Laine Mar 1 '16 at 7:11
  • Sami is right : opening from a user's perspective or from a syscall perspective? If the former, see the below answer. If the latter, no. – schaiba Mar 1 '16 at 7:55
  • Well there's always the butterfly command for emacs... – Fiximan Mar 1 '16 at 12:40

Use the command "sed".

sed -i '<\line_no_start>,<\line_no_end>d' <\filename>

Example: To delete lines 4 to 6 from file 'sample.txt'.

sed -i '4,6d' sample.txt

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