Print the last line of a file, from the CLI

后端 未结 5 658
旧巷少年郎
旧巷少年郎 2020-12-08 06:33

How to print just the last line of a file?

5条回答
  •  没有蜡笔的小新
    2020-12-08 06:56

    You can achieve this using sed as well. However, I personally recommend using tail or awk.

    Anyway, if you wish to do by sed, here are two ways:

    Method 1:

    sed '$!d' filename
    

    Method2:

    sed -n '$p' filename
    

    Here, filename is the name of the file that has data to be analysed.

提交回复
热议问题