Get last n lines of a file, similar to tail

前端 未结 30 3096
挽巷
挽巷 2020-11-22 03:46

I\'m writing a log file viewer for a web application and for that I want to paginate through the lines of the log file. The items in the file are line based with the newest

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 04:06

    I had to read a specific value from the last line of a file, and stumbled upon this thread. Rather than reinventing the wheel in Python, I ended up with a tiny shell script, saved as /usr/local/bin/get_last_netp:

    #! /bin/bash
    tail -n1 /home/leif/projects/transfer/export.log | awk {'print $14'}
    

    And in the Python program:

    from subprocess import check_output
    
    last_netp = int(check_output("/usr/local/bin/get_last_netp"))
    

提交回复
热议问题