How to use sed to remove the last n lines of a file

前端 未结 22 796
走了就别回头了
走了就别回头了 2020-11-28 18:12

I want to remove some n lines from the end of a file. Can this be done using sed?

For example, to remove lines from 2 to 4, I can use

$ sed          


        
22条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 18:34

    I don't know about sed, but it can be done with head:

    head -n -2 myfile.txt
    

提交回复
热议问题