如何使用sed删除一个文件的最后n行 [英] How to use sed to remove the last n lines of a file
本文介绍了如何使用sed删除一个文件的最后n行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从文件末尾删除一些的 N 的线。可通过使用SED做?
I want to remove some n lines from the end of a file. Can this be done using sed?
例如,要删除2线4,我可以使用
For example, to remove lines from 2 to 4, I can use
$ sed '2,4d' file
但我不知道的行号。我可以使用delete最后一行
But I don't know the line numbers. I can delete the last line using
$sed $d file
但我想知道从最终删除的 N 的线的方式。请让我知道如何在使用SED或其他方法来做。
but I want to know the way to remove n lines from the end. Please let me know how to do that using sed or some other method.
推荐答案
我不知道 SED
,但它可以用完成头
:
I don't know about sed
, but it can be done with head
:
head -n -2 myfile.txt
这篇关于如何使用sed删除一个文件的最后n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文