我们如何在unix中删除最后7行文件

Poo*_*a25 3 unix shell awk sed

如何使用unix命令从csv文件中删除最后7行.

例如 -

abc
bffkms
slds
行开始1
行开始2
行开始3
行开始4
行开始5
行开始6
行开始7

我想从上面的文件中删除最后7行.请建议.

Ken*_*ent 9

您可以使用 head

head -n-7 file
Run Code Online (Sandbox Code Playgroud)

来自手册页:

 -n, --lines=[-]K
              print the first K lines instead of the first 10;
              with the leading '-', print all but the last K lines of each file
Run Code Online (Sandbox Code Playgroud)

喜欢:

kent$ seq 10|head -n-7
1
2
3
Run Code Online (Sandbox Code Playgroud)