No need to master sed/awk/grep/wc/... use pure Ruby -- pru (github.com) submitted 1 month ago by grosser 33 comments share all 33 comments sorted by: best [–]rubygeek 5 points 1 month ago What does this give over "ruby -n -e 'some expression'"? permalink [–]grosser[S] 2 points 1 month ago an output by default, a cleaner call, helper methods for data crunching, reducing, in-file-replacement ... have a look at the readme :) permalink parent [–]absinthe718 5 points 1 month ago I really doubt that pru will perform in the same order of magnitude in either speed or memory use when compared with sed/awk/find/grep. Some of us are old enough to have learned sed/awk/find/grep in during the Reagan administration. And we got into arguments about sed/awk/find/grep versus perl in the Clinton years. This is old hat. permalink [–]eternal_noob 10 points 1 month ago* Terrible idea. The examples are really counter-intuitive and often longer than their unix equivalent. ps -ef | grep foo | grep -v grep ps -ef | pru 'include?("foo") and not include?("pru")' Second, sed, awk, et. al are useful on their own. You can't beat the convenience of awk. cat /var/log/nginx/access_log |awk '$9 ~ 404' It is more useful to learn the "regular" ruby equivalent instead of an obscure script. See: ls -al | pru 'gsub(/5/,"five")' ls -al | ruby -pe 'gsub(/5/, "five")' Or the line count example: ls -al | pru --reduce 'size' ls -al | ruby -ne 'END {puts $.}' You can't count on rubygems being present either, but short of windows sed, awk and friends is. permalink [–]grosser[S] 3 points 1 month ago pru is targeted at people that know ruby and do not want to learn x new languages of their own just to be able to collect/format data. If you know/like all those tools pru sure seems redundant. But if you do not know them or do not like them pru can be a simple way to do things that would normally require a new script file / irb session. It shines when: - examples get more complex - you do not know the alternative sed/awk/xxx syntax - you do not want to learn how each regex flavor is different in tiny ways / needs to be escaped a bit different ruby -pe can do a lot of stuff pru can do, but pru adds many helpers that get handy when crunching data like group_by / sort_by / grouped / mean / aility to reduce and many more permalink parent [–]seydar 0 points 1 month ago Just admit that you made this for fun and learning and be done with it. It really can't beat sed/awk/grep in any fashion. permalink parent [–]weavejester 1 point 1 month ago I'm actually inclined to agree with grosser here. I don't need awk or sed often enough to remember all their syntax from memory, so using pru might work out to be faster for me than the classic awk/sed/grep combination. I'd need to try it out to be certain, however. permalink parent [–]Baramin 9 points 1 month ago I wouldn't recommend learning 'pru' instead of the classic tools, as you'll never find pru installed on a unix server anywhere, you'll have to install it yourself, meaning installing ruby first, which can be a big problem on enterprise servers. permalink [–]mwilden 2 points 1 month ago It's a good point. Non-Windows programmers simply have to learn the common Unix commandline tools as part of their job. pru is well-intentioned, but I think it will actually hurt those who use it. Like it or not, we need to know how to use grep and sed. permalink parent [–]est3est 1 point 1 month ago I actually like the idea, if the goal is just to make my work done faster. If you don't like the idea of making things easier and quicker then why would you use languages like Python or Ruby, when there is already C. But to be honest, I found examples a bit confusing at the moments. Still, this have a potential, and I am very interested where it will go... permalink [–]alterlaszlo999 4 points 1 month ago that' what i dislike in ruby community: it seems they always reinvent the wheel 'cause they have only ONE dogma. and in a way they disvalue the unix under their bottom. permalink [–]est3est 2 points 1 month ago Good luck with your attitude. permalink parent [–]alterlaszlo999 0 points 1 month ago i've been quite rude, i know, and I appreciate ruby comm. in many ways; but two more examples: 'whenever' instead of learning 'cron' syntax 'god' instead of for ex. upstart permalink parent [–]joedirt123 1 point 1 month ago 'whenever' instead of learning 'cron' syntax You can use cron syntax in whenever if you want. 'god' instead of for ex. upstart God came before upstart. Upstart is not used by all linux distros. God works on Macs. permalink parent [–]jyper 2 points 1 month ago For a while it did look like most of the major distros were adopting it(although I doubt arch/gentoo/slackware would ever use it) but now a bunch of them are switching to systemd with ubuntu sticking with upstart for now(and I'm not sure about debian). permalink parent [–]joedirt123 1 point 1 month ago I also forgot to mention that you need to be root manage those types of systems. permalink parent [–]rgh 1 point 1 month ago The Debian guys are discussing systemd but it's made hard by the fact they now support FreeBSD. systemd only works with Linux and Poettering has said he has no intention of supporting anything else. permalink parent [–]est3est 1 point 1 month ago Now, we can talk. I don't know.., 'god' sounds so much better than f.i. upstart. Enough of jokes, those gems for better or for worse, try to make things just a little bit simpler. This doesn't mean they don't value unix tools. It's your choice. And honestly, you didn't mention rake, another wheel reinvention. Would you really like to use make instead of rake in all your projects? I don't see anything bad in that kind "inventions", you just got more variety of wheels to chose from, which supposed to be a good thing. permalink parent [–]GSpotAssassin 1 point 1 month ago Whenever is really nice and even though I know Cron syntax, I prefer it for readability and codeability. Also, the real advantage of Whenever is making your scheduled jobs part of your code repo instead of having to manage a crontab file external to your repo. permalink parent [–]grosser[S] 4 points 1 month ago pru tries to bring the unix way (piping stuff around) to rubyists, if you mastered sed/awk/... then this may be unnecessary, but if you are a poor fella that only knows his ruby, it can make your life easier permalink parent [–]seydar 2 points 1 month ago oh hoorary let's generalize permalink parent [–]_random_guy_ 0 points 1 month ago Great job, kudos for that. But, there are a lot of reason why this is not a good idea - ruby is slow, for instance. Also, if you look at the examples you've written yourself, they are less concise than the grep equivalent. permalink [–]grosser[S] 2 points 1 month ago most of the examples are longer then the original, since making specialized stuff in a general-purpose language will mostly be longer then in a specialized tool. Pru is not about stuff like "grep foo | grep -v grep", but about e.g. listing all your repos sorted by watches on github ... `ls | pru '[self, `curl --silent "https://github.com/grosser/#{self}"`.match(/<li class="watchers.*?(\d+)\s*<\/a/m)[1].to_i] rescue nil' 'sort_by(&:last).reverse.map{|n,i| "#{n} => #{i}" }'` its kind of messy, but readable and I wrote it in 3min tops and I have no idea how to do this with awk/sed/grep/xxx :> permalink parent [–]mwilden 3 points 1 month ago I've said this before, and I'll keep saying it: When writing documentation, use real examples. Real examples may take more time for us readers to understand, but they'll actually help us use the tool, and, more importantly, show how valuable the tool is. permalink parent [–]_random_guy_ 1 point 1 month ago Honestly, if you want to do something as complex as that, you're better off writing a full-fledged script and then execute it (ruby script.rb). It makes no sense to do something as complex as this with a one liner, with either grep or ruby. permalink parent [–]est3est 1 point 1 month ago Honestly I can't tell the difference in terms of speed. permalink parent [–]_random_guy_ 1 point 1 month ago Try with something heavy, like grepping for "te" on the complete contents of your hard drive. permalink parent [–]rgh 2 points 1 month ago yeah, 'cause I do that everyday. Usually before breakfast, it helps me relax knowing which files contain te. permalink parent [–]_random_guy_ 1 point 1 month ago Not so unusual for me to grep my whole filesystem for .sql files. Just sayin'. permalink parent [–]projecteternity 2 points 1 month ago Fun fact, ruby regex matching is orders of magnitude slower than sed/awk/grep. The proof is kind of depressing. permalink [–]GSpotAssassin 1 point 1 month ago This is for Ruby 1.8.4. It is my understanding that Ruby >1.9 has some significant optimizations. permalink parent [–]rgh 2 points 1 month ago Having used grep/sed/awk/... for the last 15 years or so I actually think this is a nice idea. As a ruby developer and sysadm and I think there's a place for both. You have to remember that not everyone is going to master sed and awk. As incredibly powerful as they are the syntax is arcane (that's no necessarily a bad thing but if you don't use them regularly they can be hard to remember). So I suspect that this find a sweet spot with ruby devs. I for one will be adding to my toolkit. permalink [–]bigfig 1 point 1 month ago Inline perl (perl -pe "s/\w//" etc) often does what sed won't (easily), but I still use sed. Awk never suited me as it seems to fill exactly the same niche as perl, and grep /egrep will remain go-to tools for parsing logs. permalink
[–]rubygeek 5 points 1 month ago
[–]grosser[S] 2 points 1 month ago
[–]absinthe718 5 points 1 month ago
[–]eternal_noob 10 points 1 month ago*
[–]grosser[S] 3 points 1 month ago
[–]seydar 0 points 1 month ago
[–]weavejester 1 point 1 month ago
[–]Baramin 9 points 1 month ago
[–]mwilden 2 points 1 month ago
[–]est3est 1 point 1 month ago
[–]alterlaszlo999 4 points 1 month ago
[–]est3est 2 points 1 month ago
[–]alterlaszlo999 0 points 1 month ago
[–]joedirt123 1 point 1 month ago
[–]jyper 2 points 1 month ago
[–]joedirt123 1 point 1 month ago
[–]rgh 1 point 1 month ago
[–]est3est 1 point 1 month ago
[–]GSpotAssassin 1 point 1 month ago
[–]grosser[S] 4 points 1 month ago
[–]seydar 2 points 1 month ago
[–]_random_guy_ 0 points 1 month ago
[–]grosser[S] 2 points 1 month ago
[–]mwilden 3 points 1 month ago
[–]_random_guy_ 1 point 1 month ago
[–]est3est 1 point 1 month ago
[–]_random_guy_ 1 point 1 month ago
[–]rgh 2 points 1 month ago
[–]_random_guy_ 1 point 1 month ago
[–]projecteternity 2 points 1 month ago
[–]GSpotAssassin 1 point 1 month ago
[–]rgh 2 points 1 month ago
[–]bigfig 1 point 1 month ago