Skip to content

Commit fe1504c

Browse files
added 18th CLI tip
1 parent d7641dc commit fe1504c

File tree

11 files changed

+89
-8
lines changed

11 files changed

+89
-8
lines changed

README.md

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

5959
## Tips
6060

61+
* [CLI tip 18: inserting file contents using GNU sed](https://learnbyexample.github.io/tips/cli-tip-18/)
6162
* [Python tip 18: arbitrary number of arguments](https://learnbyexample.github.io/tips/python-tip-18/)
6263
* [Vim tip 16: terminal mode](https://learnbyexample.github.io/tips/vim-tip-16/)
6364
* [CLI tip 17: common and unique lines](https://learnbyexample.github.io/tips/cli-tip-17/)

about/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
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>learnbyexample</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=learnbyexample property=og:title><meta content=website property=og:type><meta content="Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets." property=og:description><meta content=https://learnbyexample.github.io property=og:url><meta content=https://learnbyexample.github.io/images/learnbyexample.png property=og:image><meta content=1280 property=og:image:width><meta content=640 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=about><p align=center><img alt=profile src=/images/lbe.png><p>Hello!👋<p>I'm <strong>Sundeep Agarwal</strong> and this is my super duper awesome programming blog. Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed.<p>I've written 12 <a href=https://learnbyexample.github.io/books/>programming books</a> and there's always another book that I'm working on. Visit <a href=https://learnbyexample.gumroad.com/>Gumroad</a> or <a href=https://leanpub.com/u/learnbyexample>Leanpub</a> to buy PDF/EPUB versions of my books. See <a href=https://github.com/learnbyexample/scripting_course#ebooks>this list</a> for free online versions.<p>Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, book announcements, deals and more (free newsletter, delivered every Friday).<p>See my <a href=https://learnbyexample.github.io/escapist-reviews/>Escapist reviews</a> blog for thoughts about fictional books (fantasy, sci-fi, etc).<p>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.</p><br><h2 id=acknowledgements>Acknowledgements</h2><ul><li>This blog has been generated using <a href=https://github.com/getzola/zola>zola</a> and uses <a href=https://github.com/getzola/even>even theme</a> with modifications<li><a href=https://commons.wikimedia.org/wiki/File:Warning_icon.svg>Warning</a> and <a href=https://commons.wikimedia.org/wiki/File:Info_icon_002.svg>Info</a> icons by <a href=https://commons.wikimedia.org/wiki/User:Amada44>Amada44</a> under public domain<li><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd>MDN: kbd</a> — CSS for <code>&LTkbd></code> tag<li><a href=https://inkscape.org/>Inkscape</a> for favicon<li><a href=https://pngquant.org/>pngquant</a> and <a href=https://github.com/RazrFalcon/svgcleaner>svgcleaner</a> for optimizing images<li>See <a href=https://github.com/learnbyexample/learnbyexample.github.io/releases/tag/v1.0>v1.0 tag</a> for the older version of the blog, which was based on <a href=https://github.com/mmistakes/so-simple-theme>So Simple Jekyll Theme</a></ul></div></div></main></div><script src=https://learnbyexample.github.io/even.js></script>
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>learnbyexample</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=learnbyexample property=og:title><meta content=website property=og:type><meta content="Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets." property=og:description><meta content=https://learnbyexample.github.io property=og:url><meta content=https://learnbyexample.github.io/images/learnbyexample.png property=og:image><meta content=1280 property=og:image:width><meta content=640 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=about><p align=center><img alt=profile src=/images/lbe.png><p>Hello!👋<p>I'm <strong>Sundeep Agarwal</strong> and this is my super duper awesome programming blog. Use <a href=https://learnbyexample.github.io/atom.xml>this link</a> for the Atom feed.<p>I've written <a href=https://learnbyexample.github.io/books/>several programming books</a> and there's always another book that I'm working on. Visit <a href=https://learnbyexample.gumroad.com/>Gumroad</a> or <a href=https://leanpub.com/u/learnbyexample>Leanpub</a> to buy PDF/EPUB versions of my books. See <a href=https://github.com/learnbyexample/scripting_course#ebooks>this list</a> for free online versions.<p>Subscribe to <a href=https://learnbyexample.gumroad.com/l/learnbyexample-weekly>learnbyexample weekly</a> for programming resources, book announcements, deals and more (free newsletter, delivered every Friday).<p>See my <a href=https://learnbyexample.github.io/escapist-reviews/>Escapist reviews</a> blog for thoughts about fictional books (fantasy, sci-fi, etc).<p>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.</p><br><h2 id=acknowledgements>Acknowledgements</h2><ul><li>This blog has been generated using <a href=https://github.com/getzola/zola>zola</a> and uses <a href=https://github.com/getzola/even>even theme</a> with modifications<li><a href=https://commons.wikimedia.org/wiki/File:Warning_icon.svg>Warning</a> and <a href=https://commons.wikimedia.org/wiki/File:Info_icon_002.svg>Info</a> icons by <a href=https://commons.wikimedia.org/wiki/User:Amada44>Amada44</a> under public domain<li><a href=https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd>MDN: kbd</a> — CSS for <code>&LTkbd></code> tag<li><a href=https://inkscape.org/>Inkscape</a> for favicon<li><a href=https://pngquant.org/>pngquant</a> and <a href=https://github.com/RazrFalcon/svgcleaner>svgcleaner</a> for optimizing images<li>See <a href=https://github.com/learnbyexample/learnbyexample.github.io/releases/tag/v1.0>v1.0 tag</a> for the older version of the blog, which was based on <a href=https://github.com/mmistakes/so-simple-theme>So Simple Jekyll Theme</a></ul></div></div></main></div><script src=https://learnbyexample.github.io/even.js></script>

atom.xml

+47-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,54 @@
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>2022-11-01T00:00:00+00:00</updated>
8+
<updated>2022-11-02T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>CLI tip 18: inserting file contents using GNU sed</title>
12+
<published>2022-11-02T00:00:00+00:00</published>
13+
<updated>2022-11-02T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/tips/cli-tip-18/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/tips/cli-tip-18/</id>
16+
<content type="html">&lt;p&gt;The &lt;code&gt;r&lt;&#x2F;code&gt; command accepts a filename as argument and when the address is satisfied, entire contents of the given file is added &lt;em&gt;after&lt;&#x2F;em&gt; the matching line. This is a robust way to add multiline text literally.&lt;&#x2F;p&gt;
17+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;$ cat ip.txt
18+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; sky
19+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; apple
20+
&lt;&#x2F;span&gt;&lt;span&gt;$ cat fav_colors.txt
21+
&lt;&#x2F;span&gt;&lt;span&gt;deep red
22+
&lt;&#x2F;span&gt;&lt;span&gt;yellow
23+
&lt;&#x2F;span&gt;&lt;span&gt;reddish
24+
&lt;&#x2F;span&gt;&lt;span&gt;brown
25+
&lt;&#x2F;span&gt;&lt;span&gt;
26+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# space between r and filename is optional
27+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# adds entire contents of &amp;#39;ip.txt&amp;#39; after each line containing &amp;#39;red&amp;#39;
28+
&lt;&#x2F;span&gt;&lt;span&gt;$ sed &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&#x2F;red&#x2F;r ip.txt&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; fav_colors.txt
29+
&lt;&#x2F;span&gt;&lt;span&gt;deep red
30+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; sky
31+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; apple
32+
&lt;&#x2F;span&gt;&lt;span&gt;yellow
33+
&lt;&#x2F;span&gt;&lt;span&gt;reddish
34+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; sky
35+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; apple
36+
&lt;&#x2F;span&gt;&lt;span&gt;brown
37+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
38+
&lt;p&gt;The &lt;code&gt;e&lt;&#x2F;code&gt; flag is the easiest way to insert file contents &lt;em&gt;before&lt;&#x2F;em&gt; the matching lines. Similar to the &lt;code&gt;r&lt;&#x2F;code&gt; command, the output of an external command (&lt;code&gt;cat&lt;&#x2F;code&gt; in the below example) is inserted literally.&lt;&#x2F;p&gt;
39+
&lt;pre data-lang=&quot;ruby&quot; style=&quot;background-color:#f5f5f5;color:#1f1f1f;&quot; class=&quot;language-ruby &quot;&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span&gt;$ sed &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;&#x2F;red&#x2F;e cat ip.txt&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; fav_colors.txt
40+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; sky
41+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; apple
42+
&lt;&#x2F;span&gt;&lt;span&gt;deep red
43+
&lt;&#x2F;span&gt;&lt;span&gt;yellow
44+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; sky
45+
&lt;&#x2F;span&gt;&lt;span&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt; apple
46+
&lt;&#x2F;span&gt;&lt;span&gt;reddish
47+
&lt;&#x2F;span&gt;&lt;span&gt;brown
48+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
49+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; See &lt;a href=&quot;https:&#x2F;&#x2F;learnbyexample.github.io&#x2F;learn_gnused&#x2F;adding-content-from-file.html&quot;&gt;Adding content from file&lt;&#x2F;a&gt; chapter from my &lt;strong&gt;GNU sed&lt;&#x2F;strong&gt; ebook for many more examples, gotchas, details about the &lt;code&gt;R&lt;&#x2F;code&gt; command and so on.&lt;&#x2F;p&gt;
50+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
51+
&lt;p align=&quot;center&quot;&gt;&lt;iframe width=&quot;560&quot; height=&quot;315&quot; loading=&quot;lazy&quot; src=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;embed&#x2F;p1CFOCs3gGM&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;&#x2F;iframe&gt;&lt;&#x2F;p&gt;
52+
&lt;br&gt;
53+
&lt;p&gt;&lt;img src=&quot;&#x2F;images&#x2F;info.svg&quot; alt=&quot;info&quot; &#x2F;&gt; See also my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;learn_gnused&quot;&gt;GNU sed&lt;&#x2F;a&gt; ebook.&lt;&#x2F;p&gt;
54+
</content>
55+
</entry>
1056
<entry xml:lang="en">
1157
<title>Computing from the Command Line book announcement</title>
1258
<published>2022-11-01T00:00:00+00:00</published>

sitemap.xml

+4
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@
417417
<loc>https://learnbyexample.github.io/tips/cli-tip-17/</loc>
418418
<lastmod>2022-10-12</lastmod>
419419
</url>
420+
<url>
421+
<loc>https://learnbyexample.github.io/tips/cli-tip-18/</loc>
422+
<lastmod>2022-11-02</lastmod>
423+
</url>
420424
<url>
421425
<loc>https://learnbyexample.github.io/tips/cli-tip-2/</loc>
422426
<lastmod>2022-05-27</lastmod>

0 commit comments

Comments
 (0)