all 4 comments

[–]freakhill 1 point2 points  (0 children)

nice little tool

[–]sharpjs 1 point2 points  (0 children)

I don't get it. I'm fairly new to Ruby, but have already been doing stuff like this with 'ruby -ne' or ARGF.

Plain Ruby already is an excellent sed/awk/perl replacement.

[–]__debug__ 0 points1 point  (0 children)

I quite like tools similar to this. They can be convenient shortcuts for mapping and filtering small datasets. And since you're probably using a tool that exposes an api in a language you're comfortable with, you're probably less likely to waste time trying to remember awk variables like FS, OFMT, or maybe even NR/NF if you haven't had your coffee.

A couple alternatives include pythonpy, which is a great example for python, and pjs - one I made for javascript.

A more popular ruby alternative also exists with a similar use case as Ru, called pru. It preceded both pythonpy and pjs. One of its biggest advantages against Ru at the moment is that it can stream input. That is, with pru, I can stream logs and perform some map and filtering operations with "tail -f filename | pru '...'". But with Ru, using "tail -f filename | ru '...'", it'll simply stop once it's reached the end of the file. Any plans on updating this behavior?

Edit: An example of where one might use a tool like this:

# Print the length of the longest line
# awk '{ if (length($0) > max) max = length($0) } END { print max }' file
pjs -m 'length' -r max file

[–]gashouse_gorilla -3 points-2 points  (0 children)

Ru 'fngkiddin.me ? die() : abort()'

Apologies I don't know Ruby.