Skip to content

Commit ffbbf8a

Browse files
updated ebook section
1 parent 7f3d5e2 commit ffbbf8a

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

β€Žatom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
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-02-18T00:00:00+00:00</updated>
8+
<updated>2025-02-20T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
1010
<entry xml:lang="en">
1111
<title>GNU awk idioms explained</title>
1212
<published>2025-02-18T00:00:00+00:00</published>
13-
<updated>2025-02-18T00:00:00+00:00</updated>
13+
<updated>2025-02-20T00:00:00+00:00</updated>
1414
<link rel="alternate" href="https://learnbyexample.github.io/awk-idioms-explained/" type="text/html"/>
1515
<id>https://learnbyexample.github.io/awk-idioms-explained/</id>
1616
<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;
@@ -181,8 +181,8 @@
181181
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
182182
&lt;p&gt;See &lt;a href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;gawk&#x2F;manual&#x2F;gawk.html#Strings-And-Numbers&quot;&gt;gawk manual: How awk Converts Between Strings and Numbers&lt;&#x2F;a&gt; for more details.&lt;&#x2F;p&gt;
183183
&lt;br&gt;
184-
&lt;h2 id=&quot;linux-cli-ebooks&quot;&gt;Linux CLI ebooks&lt;a class=&quot;zola-anchor&quot; href=&quot;#linux-cli-ebooks&quot; aria-label=&quot;Anchor link for: linux-cli-ebooks&quot;&gt;πŸ”—&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
185-
&lt;p&gt;Check out &lt;a href=&quot;https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books&#x2F;&quot;&gt;my ebooks&lt;&#x2F;a&gt; if you are interested in learning more about Linux CLI basics, coreutils, text processing tools like &lt;code&gt;GNU grep&lt;&#x2F;code&gt;, &lt;code&gt;GNU sed&lt;&#x2F;code&gt;, &lt;code&gt;GNU awk&lt;&#x2F;code&gt; and &lt;code&gt;perl&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
184+
&lt;h2 id=&quot;programming-ebooks&quot;&gt;Programming ebooks&lt;a class=&quot;zola-anchor&quot; href=&quot;#programming-ebooks&quot; aria-label=&quot;Anchor link for: programming-ebooks&quot;&gt;πŸ”—&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
185+
&lt;p&gt;Check out &lt;a href=&quot;https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;books&#x2F;&quot;&gt;my ebooks&lt;&#x2F;a&gt; on Regular Expressions, Linux CLI tools, Python and Vim. You can get them all as a single bundle via &lt;a href=&quot;https:&#x2F;&#x2F;leanpub.com&#x2F;b&#x2F;learnbyexample-all-books&quot;&gt;leanpub&lt;&#x2F;a&gt; or &lt;a href=&quot;https:&#x2F;&#x2F;learnbyexample.gumroad.com&#x2F;l&#x2F;all-books&quot;&gt;gumroad&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
186186
</content>
187187
</entry>
188188
<entry xml:lang="en">

β€Žawk-idioms-explained/index.html

+2-2
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/#linux-cli-ebooks>Linux CLI 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>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}'
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
@@ -109,4 +109,4 @@
109109
</span></code></pre><p>Similarly, you can concatenate a string to a number to force string context.<pre class=language-ruby data-lang=ruby style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-ruby data-lang=ruby><span>$ awk </span><span style=color:#d07711;>'BEGIN{n1="5.0"; n2=5; if(n1==n2) print "equal"}'
110110
</span><span>$ awk </span><span style=color:#d07711;>'BEGIN{n1="5.0"; n2=5; if(n1==n2".0") print "equal"}'
111111
</span><span>equal
112-
</span></code></pre><p>See <a href=https://www.gnu.org/software/gawk/manual/gawk.html#Strings-And-Numbers>gawk manual: How awk Converts Between Strings and Numbers</a> for more details.</p><br><h2 id=linux-cli-ebooks>Linux CLI ebooks<a aria-label="Anchor link for: linux-cli-ebooks" class=zola-anchor href=#linux-cli-ebooks>πŸ”—</a></h2><p>Check out <a href=https://learnbyexample.github.io/books/>my ebooks</a> if you are interested in learning more about Linux CLI basics, coreutils, text processing tools like <code>GNU grep</code>, <code>GNU sed</code>, <code>GNU awk</code> and <code>perl</code>.</div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/gnu-awk/>#gnu-awk</a><a href=https://learnbyexample.github.io/tags/linux/>#linux</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/understanding-python-regex-announcement/>Understanding Python re(gex)? book announcement β†’</a><br></div><hr color=#e6e6e6><p>πŸ“° Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> βœ… Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> πŸ“§ Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>
112+
</span></code></pre><p>See <a href=https://www.gnu.org/software/gawk/manual/gawk.html#Strings-And-Numbers>gawk manual: How awk Converts Between Strings and Numbers</a> for more details.</p><br><h2 id=programming-ebooks>Programming ebooks<a aria-label="Anchor link for: programming-ebooks" class=zola-anchor href=#programming-ebooks>πŸ”—</a></h2><p>Check out <a href=https://learnbyexample.github.io/books/>my ebooks</a> on Regular Expressions, Linux CLI tools, Python and Vim. You can get them all as a single bundle via <a href=https://leanpub.com/b/learnbyexample-all-books>leanpub</a> or <a href=https://learnbyexample.gumroad.com/l/all-books>gumroad</a>.</div><div class=post-footer><div class=post-tags><a href=https://learnbyexample.github.io/tags/gnu-awk/>#gnu-awk</a><a href=https://learnbyexample.github.io/tags/linux/>#linux</a></div><hr color=#e6e6e6><div class=post-nav><p><a class=next href=https://learnbyexample.github.io/understanding-python-regex-announcement/>Understanding Python re(gex)? book announcement β†’</a><br></div><hr color=#e6e6e6><p>πŸ“° Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed. <br> βœ… Follow me on <a href=https://twitter.com/learn_byexample>Twitter</a>, <a href=https://github.com/learnbyexample>GitHub</a> and <a href=https://www.youtube.com/c/learnbyexample42>Youtube</a> for interesting tech nuggets. <br> πŸ“§ Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, tips, tools, free ebooks and more (free newsletter, delivered every Friday).<hr color=#e6e6e6></div></article></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

β€Žsitemap.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</url>
2929
<url>
3030
<loc>https://learnbyexample.github.io/awk-idioms-explained/</loc>
31-
<lastmod>2025-02-18</lastmod>
31+
<lastmod>2025-02-20</lastmod>
3232
</url>
3333
<url>
3434
<loc>https://learnbyexample.github.io/books/</loc>

0 commit comments

Comments
Β (0)