Think before you speak, read before you think.

linux显示最后一行的几种方法

1. tail -n 1 filename
2. tail -1 filename
3. sed -n '$p' filename
4. awk 'END {print}' filename

如果想显示文本的某一行,比如说第五行:

awk '{ if(NR==5)print}' filename

在shell中用变量LineNo代替行号,注意单双引号

awk "{ if(NR==$LineNo)print}" filename

5.如果要动态的显示最后一行

 tailf -1 filename

或几行

 tail -f filename

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *