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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Show HN: Jacinda, a functional Awk (text stream processing on the comamnd-line)

81 点作者 vmchale大约 1 年前
Typed, functional (folds, scans) stream processing backed by Andrew Gallant&#x2F;burntsushi&#x27;s regular expressions library.<p>There&#x27;s a guide here! <a href="https:&#x2F;&#x2F;vmchale.github.io&#x2F;jacinda&#x2F;" rel="nofollow">https:&#x2F;&#x2F;vmchale.github.io&#x2F;jacinda&#x2F;</a>

4 条评论

jdp大约 1 年前
Nice work with the guide, the bevy of examples makes it easy to digest.<p>The colon being used in multiple contexts is tricky. As I was scanning the examples I found postfix `:` doing type conversion like in `(%)\. {%&#x2F;Apple&#x2F;}{`3:}` and then I was wondering what it does when it has nothing on its left-hand side, like in `[(+)|0 [:1&quot;x]`. Then I noticed that the [ were unbalanced in the latter example, and eventually figured out that `[:` is its own operator separate from `:` and the middle `[` had nothing to do with function syntax.
dan-robertson大约 1 年前
Is there a succinct summary of what one gains from this being ‘functional’? I find the succinctness of regular awk to be a good advantage, and it feels like some of that comes from it being non-functional.<p>When I think about how I use awk, I think it’s mostly something like:<p><pre><code> awk &#x27;!a[$2]++&#x27; # first occurrence of each value in the second field </code></pre> Or<p><pre><code> awk &#x27;{a[$2]+=$3} END {for(x in a) print x, a[x]}&#x27; </code></pre> Or just as an advanced version of cut. A fourth example is something that is annoying to do in a streaming way but easy with bash: compute moving average of second field grouped by third field over span of size 20 (backwards) in first field.<p><pre><code> awk &#x27;{ print $1, $3, 1, $2; print $1+20, $3, -1, -$2}&#x27; | sort -n | awk &#x27;{ a[$2]+=$3; b[$2]+=$4; print $1, $2, b[$2]&#x2F;a[$2] }&#x27; </code></pre> The above all feel somewhat functional as computations – the first is a folding filter, the second a fold, the third a map, and the fourth is a folding concat map if done on-line or a concat map followed and a folding map as written.<p>The awk features that feel ‘non-functional’ to me are less the mutation and more operations like next, or the lack of compositionality: one can’t write an awk program that is, in some sense made of several awk programs (i.e sets of pattern–expr rules) joined together. That compositionality is the main advantage, in my opinion, of the ‘functional’ jq, which feels somewhat awk-adjacent. Is there some way to get composition of ja programs without falling back to byte streams in between?
评论 #40327698 未加载
gleenn大约 1 年前
Maybe spell check that title
评论 #40326435 未加载
asicsp大约 1 年前
See also: <a href="https:&#x2F;&#x2F;github.com&#x2F;gelisam&#x2F;hawk">https:&#x2F;&#x2F;github.com&#x2F;gelisam&#x2F;hawk</a> - Transform text from the command-line using Haskell expressions. Similar to awk, but using Haskell as the text-processing language.
评论 #40326439 未加载