4 ms·
tail can be done in ruby can be quite succinctly with the $< (ARGF) variable: ruby -e'$><<$<.map.last(10)' For the rest of the ruby one-liners in the page t
by nabb 15y ago
tail can be done in ruby can be quite succinctly with the $< (ARGF) variable:
ruby -e'$><<$<.map.last(10)'
For the rest of the ruby one-liners in the page the author references, most can be done more easily with standard command line tools (although most people aren't well-versed in sed, so 'ruby -pe puts' might be better than 'sed G').
- viraptor 15y agoThere's one big problem with code like that. If you're doing devops-y stuff, then you really, really don't want to debug something like that when your pager goes off at 3am. The cleaner the solution the better, because after you wake up `$><<$<` is just a blurred thing with no meaning...
- davnola 15y agoCool. That hurts my eyes. ruby -e "print ARGF.readlines.last(10)"
- rytis 15y agoon, say, a 5GB log file?.. If I read this correctly (http://www.ruby-doc.org/core/classes/IO.html#M000914 http://www.ruby-doc.org/core/classes/IO.html#M000914) it'll read the whole file into an array, then spit out last 10 entries?
- davnola 15y agoYes it does - good point, but the sigil-tastic snippet in the parent reads the whole file into an array, too - it's just harder to tell. Plus the parent snippet is not Ruby 1.9 compatible. Anyways, my version was just to illustrate that sysadmin scripting in Ruby does not have illegible.