在Ruby中读取文件的最后n行? [英] Reading the last n lines of a file in Ruby?
本文介绍了在Ruby中读取文件的最后n行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
如果在* nix系统上 tail
,您可以像这样作弊:
last_25_lines =`tail - n 25 whatever.txt`
I need to read the last 25 lines from a file (for displaying the most recent log entries). Is there anyway in Ruby to start at the end of a file and read it backwards?
解决方案
If on a *nix system with tail
, you can cheat like this:
last_25_lines = `tail -n 25 whatever.txt`
这篇关于在Ruby中读取文件的最后n行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文