3 ms·
I have no idea what this is doing, but it sure looks interesting.
by nerdponx 8y ago
I have no idea what this is doing, but it sure looks interesting.
- tptacek 8y agoIt's using Ruby to replace Awk, the way Perl once tried to.
- gfodor 8y agoTechnically Ruby tried to replace Perl, so I guess the shoe fits. It sure has taken a while for someone to do this!
- star-techate 8y agoWell the thing is, matz did it a decade ago when he carefully copied all these features that Perl came up with or itself carefully copied from awk and sed.
- Annatar 8y agoWhy the hell would anybody want to replace AWK? It’s super fast, extremely light on resources, doesn’t have any dependencies, does auto memory management and type inference, and is extremely powerful for large dataset processing, not to mention easy to learn and program.
- damagednoob 8y ago> easy to learn and program I think that's relative and it certainly hasn't been my experience. If I program in Ruby, Node, Python, etc for 8 hours of every day, it makes sense that I would reach for that over a command line tool with a syntax that looks a bit arcane. The best tool for the job sometimes is the tool you know best.
- DarkWiiPlayer 8y ago> The best tool for the job sometimes is the tool you know best. That's like hammering in screws because you know your hammer and screwdrivers seem arcane to you. For ad-hoc stuff `ruby -e` is more than enough, and if you want to write a program once and use it a lot, it's worth investing the time in doing it the way it works best, which in this case, would be a (fast) language like awk that makes it easier to process line-by-line instead of reading until EOF and making the rest of the pipeline wait.
- Annatar 8y agoIt’s arcane only if you don’t know C. If you’re on a UNIX-like or a true UNIX system, not knowing C will come to haunt you with a vengeance sooner or later.
- tragomaskhalos 8y agoI want to say that Perl, and Ruby, and even Python are superior tools .... except that awk is also my default go-to for pipiing into to munge output data, so yes it's clearly still hitting the sweet spot for many tasks.
- deleted 8y ago[deleted]
- simonista 8y agoIt's feeding stdin to ruby code you specify on the command line, either as an array of lines, or repeated strings. So in: docker ps | rb drop 1 | rb -l split[1] The output of docker ps is passed as an array of lines to ruby, and the first line is dropped, and then that output is fed to ruby again, but line by line, so each line is split (which defaults to split on whitespace), and returns the second element. With parentheses for function calls it would be: docker ps | rb drop(1) | rb -l split()[1]
- nerdponx 8y agoSo drop is just a Ruby function? This is a great idea, seems like a good application of Ruby's syntax.