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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Fascination with AWK

31 点作者 benhoyt大约 2 年前

3 条评论

prosaic-hacker大约 2 年前
Perl and Python have syntax options that are similar to the style of awk. The style was described to me as filter thinking. These were not tested on real data.<p>The awk program translates to<p>#!&#x2F;usr&#x2F;bin&#x2F;perl<p>while (&lt;&gt;) {<p><pre><code> push @freq, (split)[2..-1] if &#x2F;Frequencies&#x2F;; push @fc, (reverse(split))[3..-1] if &#x2F;Frc consts&#x2F;; push @ir, (reverse(split))[3..-1] if &#x2F;IR Inten&#x2F;; </code></pre> }<p>print &quot;@freq[$_ - 1] $fc[$_] $ir[$_]\n&quot; for 1..@freq;<p>and in python<p>#!&#x2F;usr&#x2F;bin&#x2F;env python3<p>import sys<p>freq = []<p>fc = []<p>ir = []<p>for line in sys.stdin:<p><pre><code> fields = line.split() if &quot;Frequencies&quot; in line: freq.extend(fields[2:]) elif &quot;Frc consts&quot; in line: fc.extend(reversed(fields[3:])) elif &quot;IR Inten&quot; in line: ir.extend(reversed(fields[3:])) </code></pre> for i in range(len(freq)):<p><pre><code> print(freq[i], fc[i], ir[i])</code></pre>
elenaferrantes大约 2 年前
I always use it in pipelines to extract columns. I often use it for summations of numbers. Sometimes for more complex tasks. Get the job done.
andrewstuart大约 2 年前
Awk and ChatGPT were made for each other.