Skip to content

Commit 3aa692f

Browse files
updated awk idioms post
1 parent 3cdc0b6 commit 3aa692f

File tree

9 files changed

+14
-11
lines changed

9 files changed

+14
-11
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ I'm addicted to reading fantasy/sci-fi books, so I have a [blog](https://learnby
77
## Posts
88

99
* [CLI text processing with GNU awk book announcement](https://learnbyexample.github.io/cli-text-processing-awk-announcement/)
10-
* [GNU awk idioms explained](https://learnbyexample.github.io/awk-idioms-explained/)
10+
* [awk idioms explained](https://learnbyexample.github.io/awk-idioms-explained/)
1111
* [Understanding Python re(gex)? book announcement](https://learnbyexample.github.io/understanding-python-regex-announcement/)
1212
* [Coloring matched portions with GNU grep, sed and awk](https://learnbyexample.github.io/coloring-matched-portions-grep-sed-awk/)
1313
* [100 Page Python Intro book announcement](https://learnbyexample.github.io/100-page-python-intro-book-announcement/)

atom.xml

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/>
66
<link href="https://learnbyexample.github.io"/>
77
<generator uri="https://www.getzola.org/">Zola</generator>
8-
<updated>2025-03-26T00:00:00+00:00</updated>
8+
<updated>2025-03-28T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
1010
<entry xml:lang="en">
1111
<title>CLI text processing with GNU awk book announcement</title>
@@ -95,12 +95,15 @@
9595
</content>
9696
</entry>
9797
<entry xml:lang="en">
98-
<title>GNU awk idioms explained</title>
98+
<title>awk idioms explained</title>
9999
<published>2025-02-18T00:00:00+00:00</published>
100-
<updated>2025-02-20T00:00:00+00:00</updated>
100+
<updated>2025-03-28T00:00:00+00:00</updated>
101101
<link rel="alternate" href="https://learnbyexample.github.io/awk-idioms-explained/" type="text/html"/>
102102
<id>https://learnbyexample.github.io/awk-idioms-explained/</id>
103103
<content type="html">&lt;p&gt;Do you find &lt;code&gt;awk&lt;&#x2F;code&gt; one-liners cryptic? Stuff like &lt;code&gt;!a[$0]++&lt;&#x2F;code&gt;, &lt;code&gt;1&lt;&#x2F;code&gt;, &lt;code&gt;$1=$1&lt;&#x2F;code&gt;, &lt;code&gt;NR==FNR&lt;&#x2F;code&gt; and &lt;code&gt;-v RS=&lt;&#x2F;code&gt;? You&#x27;ll find examples and brief explanations for such idioms in this post.&lt;&#x2F;p&gt;
104+
&lt;blockquote&gt;
105+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;warning.svg&quot; alt=&quot;warning&quot; &#x2F;&gt; The examples presented here have been tested with &lt;code&gt;GNU awk&lt;&#x2F;code&gt;. These are likely to work with most other implementations of &lt;code&gt;awk&lt;&#x2F;code&gt; as well.&lt;&#x2F;p&gt;
106+
&lt;&#x2F;blockquote&gt;
104107
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;br&gt;
105108
&lt;h2 id=&quot;awk-command-structure&quot;&gt;awk command structure&lt;a class=&quot;zola-anchor&quot; href=&quot;#awk-command-structure&quot; aria-label=&quot;Anchor link for: awk-command-structure&quot;&gt;🔗&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
106109
&lt;pre style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot;&gt;&lt;code&gt;&lt;span&gt;awk &amp;#39;cond1{action1} cond2{action2} ... condN{actionN}&amp;#39;

awk-idioms-explained/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>GNU awk idioms explained</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="GNU awk idioms explained" property=og:title><meta content=website property=og:type><meta content="Examples and brief explanations for cryptic awk one-liners." property=og:description><meta content=https://learnbyexample.github.io/awk-idioms-explained/ property=og:url><meta property=og:image><meta property=og:image:width><meta property=og:image:height><meta content=summary_large_image property=twitter:card><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#awk-command-structure>awk command structure</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#regexp-filtering>Regexp filtering</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#idiomatic-use-of-1>Idiomatic use of 1</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#special-variables>Special variables</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#removing-duplicates>Removing duplicates</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#rebuild-0>Rebuild $0</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#paragraph-mode>Paragraph mode</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#two-file-processing>Two file processing</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#forcing-string-and-numeric-context>Forcing string and numeric context</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#programming-ebooks>Programming ebooks</a></ul></nav></div></div><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/awk-idioms-explained/>GNU awk idioms explained</a></h1><div class=post__meta><span class=post__time>2025-02-18</span></div></header><div class=post-content><p>Do you find <code>awk</code> one-liners cryptic? Stuff like <code>!a[$0]++</code>, <code>1</code>, <code>$1=$1</code>, <code>NR==FNR</code> and <code>-v RS=</code>? You'll find examples and brief explanations for such idioms in this post.</p><span id=continue-reading></span><br><h2 id=awk-command-structure>awk command structure<a aria-label="Anchor link for: awk-command-structure" class=zola-anchor href=#awk-command-structure>🔗</a></h2><pre style=background-color:#f5f5f5;color:#1f1f1f;><code><span>awk 'cond1{action1} cond2{action2} ... condN{actionN}'
1+
<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>awk idioms explained</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content="awk idioms explained" property=og:title><meta content=website property=og:type><meta content="Examples and brief explanations for cryptic awk one-liners." property=og:description><meta content=https://learnbyexample.github.io/awk-idioms-explained/ property=og:url><meta property=og:image><meta property=og:image:width><meta property=og:image:height><meta content=summary_large_image property=twitter:card><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#awk-command-structure>awk command structure</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#regexp-filtering>Regexp filtering</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#idiomatic-use-of-1>Idiomatic use of 1</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#special-variables>Special variables</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#removing-duplicates>Removing duplicates</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#rebuild-0>Rebuild $0</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#paragraph-mode>Paragraph mode</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#two-file-processing>Two file processing</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#forcing-string-and-numeric-context>Forcing string and numeric context</a><li><a class=toc-link href=https://learnbyexample.github.io/awk-idioms-explained/#programming-ebooks>Programming ebooks</a></ul></nav></div></div><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/awk-idioms-explained/>awk idioms explained</a></h1><div class=post__meta><span class=post__time>2025-02-18</span></div></header><div class=post-content><p>Do you find <code>awk</code> one-liners cryptic? Stuff like <code>!a[$0]++</code>, <code>1</code>, <code>$1=$1</code>, <code>NR==FNR</code> and <code>-v RS=</code>? You'll find examples and brief explanations for such idioms in this post.<blockquote><p><img alt=warning src=/images/warning.svg> The examples presented here have been tested with <code>GNU awk</code>. These are likely to work with most other implementations of <code>awk</code> as well.</blockquote><span id=continue-reading></span><br><h2 id=awk-command-structure>awk command structure<a aria-label="Anchor link for: awk-command-structure" class=zola-anchor href=#awk-command-structure>🔗</a></h2><pre style=background-color:#f5f5f5;color:#1f1f1f;><code><span>awk 'cond1{action1} cond2{action2} ... condN{actionN}'
22
</span></code></pre><p>When a conditional expression isn't provided, the action is always executed. When an action isn't provided, the <code>$0</code> variable (which has the contents of the current record being processed) is printed if the conditional expression evaluates to true.</p><br><h2 id=regexp-filtering>Regexp filtering<a aria-label="Anchor link for: regexp-filtering" class=zola-anchor href=#regexp-filtering>🔗</a></h2><pre class=language-ruby data-lang=ruby style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-ruby data-lang=ruby><span style=color:#7f8989;># same as: grep 'at' and sed -n '/at/p'
33
</span><span>$ </span><span style=color:#b39f04;>printf </span><span style=color:#d07711;>'gate\napple\nwhat\nkite\n' </span><span style=color:#72ab00;>|</span><span> awk </span><span style=color:#d07711;>'/at/'
44
</span><span>gate

0 commit comments

Comments
 (0)