3 ms·
Here's the equivalent for Ruby: alias glorp='ruby -ane ' $ [data is generated] | glorp ' ~ /Something/ and puts $F[2]' Or: $ echo -e '{"hello":"
by vidarh 9y ago
Here's the equivalent for Ruby:
alias glorp='ruby -ane '
$ [data is generated] | glorp ' ~ /Something/ and puts $F[2]'
Or:
$ echo -e '{"hello":"world"}\n{"hello":"cat"}' | glorp 'puts JSON.load($_)["hello"] ' -rjson
(Of course Ruby got the -a autosplit-mode and the -n assumed 'while gets(); ... end' loop from Perl along with $_ and $F, so it's very intentional that they're similar)
- Ultimatt 9y agoAwesome thanks for sharing this! I was too lazy to give a Ruby example alongside.
- kolodny 9y agoSomewhat related nodejs self plug: Use nip https://github.com/kolodny/nip https://github.com/kolodny/nip $ echo -e 'this\nis\na\nwhatever foo' | nip 'return /whatever/.test(line) && cols[1]' # foo
- jedisct1 9y agoAnd Ruby regexes are amazing.
- omaranto 9y agoI thought that they were amazing because they were just like Perl's. Are there any differences?