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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Awk: The Power and Promise of a 40-Year-Old Language

251 点作者 jangid超过 3 年前

22 条评论

asicsp超过 3 年前
HN discussion threads for some of the links mentioned in the article:<p>* Using AWK and R to parse 25TB - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20293579" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=20293579</a><p>* Command-line Tools can be 235x Faster than a Hadoop Cluster - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17135841" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17135841</a><p>* The State of the AWK - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23240800" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23240800</a><p>For awk alternative implementations, I&#x27;m keeping an eye on frawk [0]. Aims to be faster, supports csv, etc.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;ezrosent&#x2F;frawk" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ezrosent&#x2F;frawk</a>
评论 #28449078 未加载
vyuh超过 3 年前
&quot;A good programmer uses the most powerful tool to do a job. A great programmer uses the least powerful tool that does the job.&quot; I believe this, and I always try to find the combination of simple and lightweight tools which does the job at hand correctly.<p>Awk sometimes proves surprisingly powerful. Just look at the concision of this awk one liner doing a fairly complex job:<p><pre><code> zcat large.log.gz | awk &#x27;{print $0 | &quot;gzip -v9c &gt; large.log-&quot;$1&quot;_&quot;$2&quot;.gz&quot;}&#x27; # Breakup compressed log by syslog date and recompress. #awksome </code></pre> Taken from: <a href="https:&#x2F;&#x2F;mobile.twitter.com&#x2F;climagic&#x2F;status&#x2F;614153897230397440" rel="nofollow">https:&#x2F;&#x2F;mobile.twitter.com&#x2F;climagic&#x2F;status&#x2F;61415389723039744...</a>
评论 #28447321 未加载
评论 #28447467 未加载
评论 #28450310 未加载
phkahler超过 3 年前
I never use Awk until last year. I wanted to monitor an embedded device with little more than bustbox and python on it. There was quite a bit of information in the log files (I had already written a custom log file viewer with some highlighting) but I wanted to monitor in real-time. Somehow I decided to use Awk to monitor the tail of the log file and do realtime bar-graphs by generating appropriate cursor control sequences. In the end I had about 50 lines of Awk to upload to the board and run a command to pipe the log into it - very minimally invasive and very informative.<p>Would recommend learning Awk with some kind of real-world use of your own. BTW it reminded me of using XSLT which I think is another often overlooked &quot;good thing&quot;.
评论 #28447825 未加载
评论 #28448406 未加载
zeveb超过 3 年前
&gt; Very few people still code with the legacies of the 1970s: ML, Pascal, Scheme, Smalltalk.<p>Arguably, the software world would be better off if more people <i>did</i> code with those 1970s languages, than with the ones we are stuck with now.<p>And that applies to Awk, too. As the author quotes Neil Ormos stating, Awk is well suited for <i>personal computing</i>, something which we have gotten further and further from at the same time as computers have become more distributed. At what point in history have such a large fraction of the human race had the ability to calculate to such an amazing order of magnitude, and at what point in history have such a large fraction of the same human race not bothered with calculation?<p>Awk is a great tool precisely because it puts quite a lot of expressive power in the hands of an average user on a Unix system. Sure, on a Lisp machine or Smalltalk machine there really isn&#x27;t the same need for Awk: the systems languages on such machines are safe enough and expressive enough to do what Awk does. But in the Unix context — which is basically what we&#x27;re all living in, with even the VMS-derived Windows more-or-less adhering to the Unix model — Awk is a godsend.<p>edit: correct typo
评论 #28450497 未加载
tyingq超过 3 年前
Gawk&#x27;s ability to extend it with C code is interesting as well, and pretty straightforward.<p>Here&#x27;s the source for the fork() extension that ships with gawk...it&#x27;s ~150 lines or so: <a href="https:&#x2F;&#x2F;git.savannah.gnu.org&#x2F;cgit&#x2F;gawk.git&#x2F;tree&#x2F;extension&#x2F;fork.c" rel="nofollow">https:&#x2F;&#x2F;git.savannah.gnu.org&#x2F;cgit&#x2F;gawk.git&#x2F;tree&#x2F;extension&#x2F;fo...</a><p>I was able to make a (terrible&#x2F;joke&#x2F;but-it-kinda-works) web server with gawk using the extensions that ship with it: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255#gistcomment-3143007" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255#gistcomment-3143007</a>
评论 #28446622 未加载
dugmartin超过 3 年前
My first and only real use of awk was around 1995. I was working at a new job doing embedded software work at GE and we had a lot of documentation in SGML, written&#x2F;viewed using Interleaf. Interleaf was super slow on the HP-UX workstations we had and iirc search was even slower. I got the idea to convert all the SGML files into a single HTML file and I reached for awk as I had used it for some one-liners previously. I ended up writing an awk script that generated a frameset with one sidebar frame that was a treeish table of contents and the other frame the mondo html file with anchors for the table of contents. It loaded pretty fast in the HP-UX browser and search was really fast.
dekhn超过 3 年前
I&#x27;ve used Python almost my entire career, but started with out the UNIX tools. I never found awk interesting, then took a peek at it recently and understood: this was <i>the</i> pre-perl! it had scripting-language hash tables!
评论 #28447225 未加载
zeteo超过 3 年前
My company mandates Windows but Git Bash has been a backdoor into Unix tools and I&#x27;ve recently learned sed and awk to take full advantage of it. You need to think a bit about your one liners and they&#x27;ll always feel very hacky, but sed&#x2F;awk (with a bit of sort thrown in) are an amazingly powerful combination for dealing with all sorts of messy data dumps. In 10 minutes I can craft a one liner that replaces a 2 hours C# console app and runs just as fast. And, surprisingly, I often find it easier to go back months later and understand the messy looking one liner than the nicely formatted, well commented, unit tested console app.
jrochkind1超过 3 年前
My first job getting paid to program was in awk. Processing log files.<p>In the middle of that job, my supervsior, you know what, we&#x27;re doing increasingly complicated things with awk and it&#x27;s getting increasingly hacky... I&#x27;ve heard that Perl is like awk but better, do you want to learn Perl and switch to that?<p>And so we did. My thought then was there was little that was easier in awk than Perl, you could use Perl very much like awk if you wanted, you can even use the right command-line args to have Perl have an &quot;implied loop&quot; like awk... but then you can do a lot more with Perl too.<p>I don&#x27;t use Perl anymore. Or awk.
评论 #28447578 未加载
melling超过 3 年前
i no longer use it but Perl was always the better solution when one thought AWK was the answer.<p>Perl will do those things where AWK really shines and if the problem got bigger, Perl was easier to deal with.
评论 #28445762 未加载
评论 #28445060 未加载
评论 #28447303 未加载
评论 #28445589 未加载
arendtio超过 3 年前
Learning awk is actually pretty simple. For years I just used the &#x27;{print $2}&#x27; version to extract fields, but after reading some short book I felt pretty confident of having understood the basics.<p>Sadly I don&#x27;t remember which book it was, but this page looks like a good start: <a href="https:&#x2F;&#x2F;ferd.ca&#x2F;awk-in-20-minutes.html" rel="nofollow">https:&#x2F;&#x2F;ferd.ca&#x2F;awk-in-20-minutes.html</a>
评论 #28449016 未加载
ketanmaheshwari超过 3 年前
My own shameless plug: <a href="https:&#x2F;&#x2F;ketancmaheshwari.github.io&#x2F;posts&#x2F;2020&#x2F;05&#x2F;24&#x2F;SMC18-Data-Challenge-4.html" rel="nofollow">https:&#x2F;&#x2F;ketancmaheshwari.github.io&#x2F;posts&#x2F;2020&#x2F;05&#x2F;24&#x2F;SMC18-Da...</a>
nesuse超过 3 年前
There&#x27;s a free awk course here for anyone interested <a href="https:&#x2F;&#x2F;www.udemy.com&#x2F;course&#x2F;awk-tutorial&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.udemy.com&#x2F;course&#x2F;awk-tutorial&#x2F;</a>
cb321超过 3 年前
When you have a standardized problem setting like the implicit loop in awk, n alternative to a whole new programming language is a simple &lt; 100 lines of code program generator [1].<p>This design lets you retain easy access to large sets of pre-existing libraries as well as have a &quot;compiled&#x2F;statically typed&quot; situation, if you want. It also leverages familiarity with your existing programming languages. I adapted a similar small program like this to emit a C program, but anything else is obviously pretty easy. Easy is good. Familiar is good.<p>Interactivity-wise, with a TinyC&#x2F;tcc fast running compiler backend my `rp` programs run sub-second from ENTER to completion on small data. Even with not optimizing tcc, they they still run faster than byte-compiled&#x2F;VM interpreted mawk&#x2F;gawk on a per input-byte basis. If you take the time to do an optimized build with gcc -O3&#x2F;etc., they can run much faster.<p>And I leave the source code around if you want to just use the program generator as a way to save keystrokes&#x2F;get a fast start on a row processing program.<p>Anyway, I&#x27;m not trying to start a language holy war, but just exhibit how if you rotate the problem (or your head looking at the problem) ever so slightly another answer exists in this space and is quite easy. :-)<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;c-blake&#x2F;cligen&#x2F;blob&#x2F;master&#x2F;examples&#x2F;rp.nim" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;c-blake&#x2F;cligen&#x2F;blob&#x2F;master&#x2F;examples&#x2F;rp.ni...</a>
torcete超过 3 年前
I use awk constantly in bioinformatics, for many of the file formats designed to store genomic data, awk is the easiest tool you can use for processing.
评论 #28447761 未加载
评论 #28449225 未加载
linuxlizard超过 3 年前
I use awk to auto-generate C header files from other header files. I work with $vendor&#x27;s huge complicated kernel driver codebase. I need small pieces of $vendor&#x27;s interconnected header files in order to make kernel calls to their drivers without pulling in all their code.
justin_oaks超过 3 年前
I only recently learned Awk enough to be useful. But I still don&#x27;t reach for it when I probably should.<p>What are the most common cases where you reach for Awk instead of some other tools?<p>I recently used it to parse and recombine data from the OpenVPN status file. That file has a few differently formatted tables in the same file. Using Awk, I was able to change a variable as each table was encountered, this I could change the Awk program behavior by which table it was operating on.
评论 #28445807 未加载
评论 #28446117 未加载
评论 #28446183 未加载
评论 #28445742 未加载
评论 #28448058 未加载
评论 #28446046 未加载
评论 #28445595 未加载
gompertz超过 3 年前
And let&#x27;s not forget about the amazing commercial offering of Awk, known as Tawk (by Thompson Automation). To this day some features from Tawk cannot be found in Gawk.
评论 #28491035 未加载
mukundesh超过 3 年前
awk is great for data analysis - usually, I start with cut, then move to awk as complexity increases and finally to python.
SjorsVG超过 3 年前
I find it very unpleasant to read Awk code. It looks as bad as regex to me.
forinti超过 3 年前
sed is pretty ancient too. I&#x27;ve used it a lot with Docker to alter parameters during builds.
shp0ngle超过 3 年前
awk is fast and really useful.<p>It&#x27;s also generally unreadable.
评论 #28445784 未加载