TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Fascination with AWK

31 pointsby benhoytabout 2 years ago

3 comments

prosaic-hackerabout 2 years ago
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>
elenaferrantesabout 2 years ago
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.
andrewstuartabout 2 years ago
Awk and ChatGPT were made for each other.