TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

AWK-ward Ruby

124 点作者 remi大约 14 年前

15 条评论

telemachos大约 14 年前
If this article has made you more curious about Awk itself, I highly recommend <i>The Awk Programming Language</i> [1] by Aho, Kernighan and Weinberger. It's a terrific book all around (look at the list of authors), and Awk really is worth knowing if you use the command line a lot. (Credit where it's due: silentbicycle always recommends this book, and I read it on his advice. But I seem to have beaten him to this thread.)<p>[1] <a href="http://cm.bell-labs.com/cm/cs/awkbook" rel="nofollow">http://cm.bell-labs.com/cm/cs/awkbook</a> (This link seems dead at the moment. I'm very much going to hope that's temporary.)
评论 #2487883 未加载
phaylon大约 14 年前
It's nice to see an article that focuses on the common strengths of programming languages, and what came out of them, instead of the usual X vs. Y content. There is often so much common ground (especially between dynamic programming languages) that many solutions and knowledge are easily transferable and could be shared as well, independent from actual code.
chubot大约 14 年前
Didn't know Ruby (and Perl?) had BEGIN and END... pretty cool. However I would just write the final example as:<p>curl -s <a href="http://www.gutenberg.org/files/1080/1080.txt" rel="nofollow">http://www.gutenberg.org/files/1080/1080.txt</a> | tr ' \t' '\n\n' | sort | uniq -c | sort -n<p>and avoid any kind of procedural programming.
评论 #2486746 未加载
评论 #2486453 未加载
gte910h大约 14 年前
Blocks come from smalltalk too: <a href="http://web.cecs.pdx.edu/~harry/musings/SmalltalkOverview.html#Blocks" rel="nofollow">http://web.cecs.pdx.edu/~harry/musings/SmalltalkOverview.htm...</a>
评论 #2488199 未加载
评论 #2486389 未加载
forkandwait大约 14 年前
Awk is one of those languages in which learning the syntax almost automatically teaches you to think differently. In Awk's case, in terms of tables, maintaining state between rows, and phases in execution while processing data. I find it as much as a mind f<i></i>* as Lisp or Prolog, though in a very workaday unixy sort of way.
评论 #2488469 未加载
grandalf大约 14 年前
This is very cool. It sort of ruins the approach I use when teaching people to program in Ruby or Python where I have them write some code to calculate stats on a text file then show them how trivial it would have been in awk.
dgulino大约 14 年前
Similar Perl/Awk syntax for Python one-liners with BEGIN/END: <a href="http://code.activestate.com/recipes/577075-pyliner-script-to-run-arbitrary-python-code-on-the/?in=user-4119417" rel="nofollow">http://code.activestate.com/recipes/577075-pyliner-script-to...</a>
评论 #2487232 未加载
przemoc大约 14 年前
Nice article. I use AWK and sed all the time. I still prefer writing some piped shell commands in one (sometimes lengthy) line than proper perl/python/ruby script, unless it's really needed. Why? It (paradoxically?) seems more natural to me in shell environments (and often can be done much more quickly that way).<p>Example of AWK usage from my old (currently unmaintained! and insecure!) pcspk project (<a href="http://download.przemoc.net/pcspk" rel="nofollow">http://download.przemoc.net/pcspk</a>) is "Siemens ringtone converter": <a href="https://gist.github.com/943386" rel="nofollow">https://gist.github.com/943386</a> (actually it requires gawk, which has nice extensions)
lloeki大约 14 年前
This is both the most useful and engaging introduction to AWK that I've read <i>and</i> the most intense deprecation signal by showing how to (almost drop-in) replace it with Ruby or Perl, which creates a terrible conflict in me.<p><i>"print $1"</i> was the most I ever used AWK. So when I read the first part (whose examples made great sense to me) I shouted "AWK is awesome! I should learn it now!". Then the last part came in and showed me how I could use a language I already know to precisely replace it. I both feel compelled that I can leverage my current knowledge right now to solve another class of problems, and sad not to learn a completely new thing.
riffraff大约 14 年前
I dare to suggest using $;=/[^a-zA-Z]+/ in the BEGIN block, then you can get away with using only split.each on the second line, and it's more perl-awk-ish :)
评论 #2486876 未加载
js2大约 14 年前
Primitive network calculator I once wrote in awk:<p><a href="https://gist.github.com/7bb70e1065f085b46a00" rel="nofollow">https://gist.github.com/7bb70e1065f085b46a00</a>
Omni5cience大约 14 年前
Is it just me or is the video of the talk at <a href="http://shellhaters.heroku.com/" rel="nofollow">http://shellhaters.heroku.com/</a> broken?<p>On closer examination I noticed the video is here <a href="http://confreaks.net/system/assets/datas/1177/original/363-gogaruco2010-the-shell-hater-s-handbook-small.mp4" rel="nofollow">http://confreaks.net/system/assets/datas/1177/original/363-g...</a>
lvvlvv大约 14 年前
Simplified C++ inspired by AWK: <a href="http://github.com/lvv/scc" rel="nofollow">http://github.com/lvv/scc</a>
regularfry大约 14 年前
Isn't there an AI course taught somewhere that only uses AWK? Sure I remember reading about that somewhere.
abecedarius大约 14 年前
It's Awk, not AWK.<p>So 'ruby -n' acts like Awk? Neat.
评论 #2486497 未加载