Skip to content

Commit a85bc48

Browse files
added 20th CLI tip, misc changes
1 parent 572881a commit a85bc48

File tree

11 files changed

+77
-11
lines changed

11 files changed

+77
-11
lines changed

Diff for: README.md

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

6363
## Tips
6464

65+
* [CLI tip 20: expand and unexpand](https://learnbyexample.github.io/tips/cli-tip-20/)
6566
* [Python tip 20: saving and loading json](https://learnbyexample.github.io/tips/python-tip-20/)
6667
* [Vim tip 18: moving within long lines](https://learnbyexample.github.io/tips/vim-tip-18/)
6768
* [CLI tip 19: extended globs](https://learnbyexample.github.io/tips/cli-tip-19/)

Diff for: atom.xml

+41-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,46 @@
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-12-09T00:00:00+00:00</updated>
8+
<updated>2022-12-14T00:00:00+00:00</updated>
99
<id>https://learnbyexample.github.io/atom.xml</id>
10+
<entry xml:lang="en">
11+
<title>CLI tip 20: expand and unexpand</title>
12+
<published>2022-12-14T00:00:00+00:00</published>
13+
<updated>2022-12-14T00:00:00+00:00</updated>
14+
<link rel="alternate" href="https://learnbyexample.github.io/tips/cli-tip-20/" type="text/html"/>
15+
<id>https://learnbyexample.github.io/tips/cli-tip-20/</id>
16+
<content type="html">&lt;p&gt;These two commands will help you convert tabs to spaces and vice versa. Both these commands support options to customize the width of tab stops and which occurrences should be converted.&lt;&#x2F;p&gt;
17+
&lt;p&gt;The default expansion aligns at multiples of &lt;code&gt;8&lt;&#x2F;code&gt; columns (calculated in terms of bytes).&lt;&#x2F;p&gt;
18+
&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 style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;apple&amp;#39; = 5 bytes, \t converts to 3 spaces
19+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;banana&amp;#39; = 6 bytes, \t converts to 2 spaces
20+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;a&amp;#39; and &amp;#39;b&amp;#39; = 1 byte, \t converts to 7 spaces
21+
&lt;&#x2F;span&gt;&lt;span&gt;$ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;printf &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;apple\tbanana\tcherry\na\tb\tc\n&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; expand
22+
&lt;&#x2F;span&gt;&lt;span&gt;apple banana cherry
23+
&lt;&#x2F;span&gt;&lt;span&gt;a b c
24+
&lt;&#x2F;span&gt;&lt;span&gt;
25+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;αλε&amp;#39; = 6 bytes, \t converts to 2 spaces
26+
&lt;&#x2F;span&gt;&lt;span&gt;$ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;printf &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39;αλε\tπού\n&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; expand
27+
&lt;&#x2F;span&gt;&lt;span&gt;αλε πού
28+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
29+
&lt;p&gt;By default, the &lt;code&gt;unexpand&lt;&#x2F;code&gt; command converts initial blank (space or tab) characters to tabs. The first occurrence of a non-blank character will stop the conversion. By default, every &lt;code&gt;8&lt;&#x2F;code&gt; columns worth of blanks is converted to a tab.&lt;&#x2F;p&gt;
30+
&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 style=&quot;color:#7f8989;&quot;&gt;# input is 8 spaces followed by &amp;#39;a&amp;#39; and then more characters
31+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# the initial 8 spaces is converted to a tab character
32+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# &amp;#39;a&amp;#39; stops any further conversion, since it is a non-blank character
33+
&lt;&#x2F;span&gt;&lt;span&gt;$ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;printf &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39; a b c\n&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; unexpand &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; cat &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;T
34+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;^&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;Ia&lt;&#x2F;span&gt;&lt;span&gt; b c
35+
&lt;&#x2F;span&gt;&lt;span&gt;
36+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# input is 9 spaces followed by &amp;#39;a&amp;#39; and then more characters
37+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# the initial 8 spaces is converted to a tab character
38+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#7f8989;&quot;&gt;# remaining space is left as is
39+
&lt;&#x2F;span&gt;&lt;span&gt;$ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#b39f04;&quot;&gt;printf &lt;&#x2F;span&gt;&lt;span style=&quot;color:#d07711;&quot;&gt;&amp;#39; a b c\n&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; unexpand &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;|&lt;&#x2F;span&gt;&lt;span&gt; cat &lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;T
40+
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#72ab00;&quot;&gt;^&lt;&#x2F;span&gt;&lt;span style=&quot;color:#5597d6;&quot;&gt;I&lt;&#x2F;span&gt;&lt;span&gt; a b c
41+
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
42+
&lt;p&gt;&lt;strong&gt;Video demo&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
43+
&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;tsJCtE6oZDs&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;
44+
&lt;br&gt;
45+
&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;cli_text_processing_coreutils&#x2F;expand-unexpand.html&quot;&gt;expand and unexpand&lt;&#x2F;a&gt; chapter my &lt;a href=&quot;https:&#x2F;&#x2F;github.com&#x2F;learnbyexample&#x2F;cli_text_processing_coreutils&quot;&gt;Command line text processing with GNU Coreutils&lt;&#x2F;a&gt; ebook for more examples, options, etc.&lt;&#x2F;p&gt;
46+
</content>
47+
</entry>
1048
<entry xml:lang="en">
1149
<title>Interactive Linux CLI Text Processing Exercises</title>
1250
<published>2022-12-09T00:00:00+00:00</published>
@@ -2888,7 +2926,7 @@
28882926
<entry xml:lang="en">
28892927
<title>Brag post: Hacker News Front Page entries</title>
28902928
<published>2022-01-21T00:00:00+00:00</published>
2891-
<updated>2022-03-16T00:00:00+00:00</updated>
2929+
<updated>2022-12-14T00:00:00+00:00</updated>
28922930
<link rel="alternate" href="https://learnbyexample.github.io/mini/hacker-news-front-page-brag/" type="text/html"/>
28932931
<id>https://learnbyexample.github.io/mini/hacker-news-front-page-brag/</id>
28942932
<content type="html">&lt;p&gt;In case you haven&#x27;t yet read this nice post &lt;a href=&quot;https:&#x2F;&#x2F;jvns.ca&#x2F;blog&#x2F;brag-documents&#x2F;&quot;&gt;&amp;quot;Get your work recognized: write a brag document&amp;quot;&lt;&#x2F;a&gt; by Julia Evans, please do that first.&lt;&#x2F;p&gt;
@@ -2907,6 +2945,7 @@
29072945
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29391107&quot;&gt;Show HN: Improve your Python regex skills with 75 interactive exercises&lt;&#x2F;a&gt; — &lt;em&gt;175 points, Nov 2021, 12 comments&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
29082946
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29837543&quot;&gt;Vim prank: alias vim=&#x27;vim -y&#x27;&lt;&#x2F;a&gt; — &lt;em&gt;341 points, Jan 2022, 259 comments&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
29092947
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30684232&quot;&gt;Vim Reference Guide&lt;&#x2F;a&gt; — &lt;em&gt;244 points, Mar 2022, 110 comments&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
2948+
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33931677&quot;&gt;Show HN: Interactive exercises for Linux CLI text processing commands&lt;&#x2F;a&gt; — &lt;em&gt;68 points, Dec 2022, 7 comments&lt;&#x2F;em&gt;&lt;&#x2F;li&gt;
29102949
&lt;&#x2F;ol&gt;
29112950
&lt;p&gt;As is the case with other social media platforms, being an active participant on Hacker News definitely helps. Apart from commenting on other topics, I also post links to projects and resources that I felt were useful. The number of such links reaching front page outnumbers my own content links.&lt;&#x2F;p&gt;
29122951
</content>

0 commit comments

Comments
 (0)