English 中文(简体)
CLI文件最后一行印刷
原标题:Print the last line of a file, from the CLI

如何仅打印文件最后一行?

最佳回答
$ cat file | awk  END{print} 

原文通过https://stackoverflow.com/users/80989”查询。

问题回答

利用适当的工具从事这项工作。 由于你想要获得档案的最后一行,细节是工作的适当工具,特别是如果你拥有大量档案的话。 在本案中,木舟卷宗处理算法更为有效。

tail -n 1 file

如果你真的想要使用 a,

awk  END{print}  file

EDIT:tail -1 file deprecated

是否需要为此使用<代码>awk? 为什么不只使用<代码>尾——n 1 我的File?

摘录档案最后一行:

  1. 编辑: www.un.org/Depts/DGACM/index_french.htm 姓名:<0>

  2. 详细情况:tail -1级档案 姓名:<0>

  3. a. 使用:子: awk END{打印} 姓名:<0>

也可通过<条码>实现。 然而,我个人建议使用<代码>尾wk

无论如何,如果你希望通过<条码>-来做,这有两种方式:

方法1:

sed  $!d  filename

方法2:

sed -n  $p  filename

在此,档案名称是可分析数据的档案名称。





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...