Hacker News new | ask | show | jobs
by brigandish 2090 days ago
You can cut that back a bit with the '-n' switch. Using an example from this helpful article[1] on some of the switches Ruby inherited from Perl:

    ps ax | ruby -e 'ARGF.each { |line| puts line.split.first if line =~ /top/ }'
becomes:

    ps ax | ruby -ne 'puts $_.split.first if $_ =~ /top/'
It even squashes the extra newline the ARGF version prints out first.

[1] https://robm.me.uk/ruby/2013/11/20/ruby-enp.html

1 comments

Well, my book linked in this post is all about using Ruby from cli, with Perl like switches.

    ps ax | ruby -ane 'puts $F[0] if /top/'
Nice, I didn't know about autosplit.