<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nam Hoang</title>
    <description>The latest articles on DEV Community by Nam Hoang (@particle4dev).</description>
    <link>https://dev.to/particle4dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F593501%2Fe3b2ec1b-cf63-4044-8917-dbeb565ece82.jpeg</url>
      <title>DEV Community: Nam Hoang</title>
      <link>https://dev.to/particle4dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/particle4dev"/>
    <language>en</language>
    <item>
      <title>Handy Sed One-Liners for Text Manipulation and Processing</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Mon, 01 Apr 2024 02:34:35 +0000</pubDate>
      <link>https://dev.to/particle4dev/handy-sed-one-liners-for-text-manipulation-and-processing-4iol</link>
      <guid>https://dev.to/particle4dev/handy-sed-one-liners-for-text-manipulation-and-processing-4iol</guid>
      <description>&lt;p&gt;FILE SPACING:&lt;/p&gt;

&lt;p&gt;Double space a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed &lt;/span&gt;G
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Double space a file which already has blank lines, output file should contain no more than one blank line between lines of text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/^$/d;G'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Triple space a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'G;G'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Undo double-spacing (assumes even-numbered lines are always blank):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'n;d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Insert a blank line above every line which matches "regex":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/regex/{x;p;x;}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Insert a blank line below every line which matches "regex":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/regex/G'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Insert a blank line above and below every line which matches "regex":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/regex/{x;p;x;G;}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NUMBERING:&lt;/p&gt;

&lt;p&gt;Number each line of a file (simple left alignment):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; filename | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'N;s/\n/\t/'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Number each line of a file (number on left, right-aligned):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; filename | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'N; s/^/     /; s/ *\(.\{6,\}\)\n/\1  /'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Number each line of file, but only print numbers if line is not blank:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/./='&lt;/span&gt; filename | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/./N; s/\n/ /'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Count lines (emulates "wc -l"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'$='&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;TEXT CONVERSION AND SUBSTITUTION:&lt;/p&gt;

&lt;p&gt;Convert DOS newlines (CR/LF) to Unix format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/.$//'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert Unix newlines (LF) to DOS format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s2"&gt;"s/&lt;/span&gt;&lt;span class="nv"&gt;$/&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="se"&gt;\\\r&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;/"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete leading whitespace (spaces, tabs) from front of each line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/^[ \t]*//'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete trailing whitespace (spaces, tabs) from end of each line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/[ \t]*$//'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete both leading and trailing whitespace from each line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/^[ \t]*//;s/[ \t]*$//'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Insert 5 blank spaces at beginning of each line (make page offset):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/^/     /'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Align all text flush right on a 79-column width:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/^.\{1,78\}$/ &amp;amp;/;ta'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Center all text in the middle of 79-column width:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt;  &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/^.\{1,77\}$/ &amp;amp; /;ta'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Substitute (find and replace) "foo" with "bar" on each line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/foo/bar/'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Substitute "foo" with "bar" EXCEPT for lines which contain "baz":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/baz/!s/foo/bar/g'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reverse order of lines (emulates "tac"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'$!G;h;$!d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Join pairs of lines side-by-side (like "paste"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'$!N;s/\n/ /'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a line ends with a backslash, append the next line to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'/\\$/N; s/\\\n//; ta'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a blank line every 5 lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gsed &lt;span class="s1"&gt;'0~5G'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SELECTIVE PRINTING OF CERTAIN LINES:&lt;/p&gt;

&lt;p&gt;Print first 10 lines of file (emulates behavior of "head"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed &lt;/span&gt;10q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print first line of file (emulates "head -1"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed &lt;/span&gt;q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print the last 10 lines of a file (emulates "tail"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'$q;N;11,$D;ba'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print only lines which match regular expression (emulates "grep"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'/regexp/p'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print only lines which do NOT match regexp (emulates "grep -v"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/regexp/!d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print paragraph if it contains AAA:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'/./{H;$!d;}'&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'x;/AAA/!d;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Print section of file from regular expression to end of file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s1"&gt;'/regexp/,$p'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SELECTIVE DELETION OF CERTAIN LINES:&lt;/p&gt;

&lt;p&gt;Print all of file EXCEPT section between 2 regular expressions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/Iowa/,/Montana/d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete duplicate, consecutive lines from a file (emulates "uniq"):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'$!N; /^\(.*\)\n\1$/!P; D'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete all blank lines from a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/^$/d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete all consecutive blank lines from file except the first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/./,/^$/!d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete all trailing blank lines at end of file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'/^\n*$/{$d;N;ba'&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'}'&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SPECIAL APPLICATIONS:&lt;/p&gt;

&lt;p&gt;Remove nroff overstrikes (char, backspace) from man pages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s2"&gt;"s/.&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\\\b&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;//g"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get Usenet/e-mail message header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/^$/q'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get Usenet/e-mail message body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'1,/^$/d'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a leading angle bracket and space to each line (quote a message):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/^/&amp;gt; /'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Delete leading angle bracket &amp;amp; space from each line (unquote a message):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'s/^&amp;gt; //'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove most HTML tags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; :a &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/&amp;lt;[^&amp;gt;]*&amp;gt;//g;/&amp;lt;/N;//ba'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extract multi-part uuencoded binaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/^end/,/^begin/d'&lt;/span&gt; file1 file2 ... fileX | uudecode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SORTING PARAGRAPHS OF FILE ALPHABETICALLY:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/./{H;d;};x;s/\n/={NL}=/g'&lt;/span&gt; file | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'1s/={NL}=//;s/={NL}=/\n/g'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OPTIMIZING FOR SPEED:&lt;br&gt;
Substitution executes more quickly if the "find" expression is specified before the "s/.../.../" instruction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="s1"&gt;'/foo/ s/foo/bar/g'&lt;/span&gt; filename
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>sed</category>
      <category>unix</category>
      <category>scripting</category>
    </item>
    <item>
      <title>A task vs a script in Hardhat</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Mon, 25 Mar 2024 08:19:38 +0000</pubDate>
      <link>https://dev.to/particle4dev/a-task-vs-a-script-in-hardhat-ekg</link>
      <guid>https://dev.to/particle4dev/a-task-vs-a-script-in-hardhat-ekg</guid>
      <description>&lt;p&gt;&lt;strong&gt;Understanding the Distinctions Between Tasks and Scripts in Hardhat&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's crucial to grasp that nearly everything achievable with a task can also be accomplished with a script, and vice versa. However, there are nuances: certain actions are exclusive to tasks or scripts, and some tasks are more suited to one or the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tasks:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One fundamental capability exclusive to tasks is the ability to override another task. For instance, consider augmenting your test workflow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;hre&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;runSuper&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Perform additional actions&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;runSuper&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What about custom tasks? In this scenario, tasks and scripts are essentially interchangeable. The primary advantage of utilizing a task lies in integrating with Hardhat's argument parser. For instance, when developing a token and needing to verify an address's balance on a specific network, you might execute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hh balance &lt;span class="nt"&gt;--address&lt;/span&gt; 00x4403B5d2Fed270D18b6d83122C818c2413D9BC05 &lt;span class="nt"&gt;--network&lt;/span&gt; mainnet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Where 'hh' represents the Hardhat shorthand.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scripts:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One distinctive feature of scripts is their executability directly via Node.js. Instead of:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hh run my-script.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have the option to use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node my-script.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This flexibility enables additional functionalities such as passing extra flags to the Node.js binary. Furthermore, it facilitates execution with alternative binaries like ts-node, ndb, or mocha.&lt;/p&gt;

&lt;p&gt;It's worth noting that when adopting this approach, explicit importation of the Hardhat Runtime Environment is necessary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hre&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hardhat&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, utilize:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--require&lt;/span&gt; hardhat/register my-scripts.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to ensure the availability of globally scoped variables, akin to those accessible when using 'hh run'.&lt;/p&gt;

&lt;p&gt;Another rationale for employing scripts is the ability to leverage alternative argument-parsing libraries like commander, rather than relying on Hardhat's built-in parser.&lt;/p&gt;

&lt;p&gt;However, bear in mind that this approach forfeits the ability to specify the network using the '--network' parameter. In such cases, setting the 'HARDHAT_NETWORK' environment variable becomes necessary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;HARDHAT_NETWORK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rinkeby node my-scripts.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding these distinctions empowers developers to choose the appropriate tool—task or script—based on the specific requirements of their development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://ethereum.stackexchange.com/questions/83656/where-does-the-line-blur-between-a-task-and-a-script-in-hardhat"&gt;https://ethereum.stackexchange.com/questions/83656/where-does-the-line-blur-between-a-task-and-a-script-in-hardhat&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hardhat</category>
      <category>smartcontract</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Blockchain Network List</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Fri, 01 Mar 2024 11:05:06 +0000</pubDate>
      <link>https://dev.to/particle4dev/blockchain-network-list-4kla</link>
      <guid>https://dev.to/particle4dev/blockchain-network-list-4kla</guid>
      <description>&lt;h2&gt;
  
  
  OP Testnet (Sepolia)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Network name:&lt;/strong&gt; OP Sepolia&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New RPC URL:&lt;/strong&gt; &lt;a href="https://sepolia.optimism.io"&gt;https://sepolia.optimism.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chain ID:&lt;/strong&gt; 11155420&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Currency symbol:&lt;/strong&gt; ETH&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block explorer URL (Optional):&lt;/strong&gt; &lt;a href="https://sepolia-optimistic.etherscan.io"&gt;https://sepolia-optimistic.etherscan.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faucet:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://learnweb3.io/faucets/optimism_sepolia/"&gt;https://learnweb3.io/faucets/optimism_sepolia/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Useful Links:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.optimism.io/chain/networks"&gt;https://docs.optimism.io/chain/networks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Base Testnet (Sepolia)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Network name:&lt;/strong&gt; Base Sepolia&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New RPC URL:&lt;/strong&gt; &lt;a href="https://sepolia.base.org"&gt;https://sepolia.base.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chain ID:&lt;/strong&gt; 84532&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Currency symbol:&lt;/strong&gt; ETH&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block explorer URL (Optional):&lt;/strong&gt; &lt;a href="https://sepolia-explorer.base.org"&gt;https://sepolia-explorer.base.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faucet:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.alchemy.com/faucets/base-sepolia"&gt;https://www.alchemy.com/faucets/base-sepolia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learnweb3.io/faucets/base_sepolia/"&gt;https://learnweb3.io/faucets/base_sepolia/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://faucet.triangleplatform.com/base/sepolia"&gt;https://faucet.triangleplatform.com/base/sepolia&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Useful Links:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.base.org/docs/network-information/"&gt;https://docs.base.org/docs/network-information/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Arbitrum Sepolia
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Network name:&lt;/strong&gt; Arbitrum Sepolia&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New RPC URL:&lt;/strong&gt; &lt;a href="https://sepolia-rollup.arbitrum.io/rpc"&gt;https://sepolia-rollup.arbitrum.io/rpc&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chain ID:&lt;/strong&gt; 421614&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Currency symbol:&lt;/strong&gt; ETH&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block explorer URL (Optional):&lt;/strong&gt; &lt;a href="https://sepolia.arbiscan.io"&gt;https://sepolia.arbiscan.io&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Useful Links:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://revoke.cash/learn/wallets/add-network/arbitrum-sepolia"&gt;Adding Arbitrum Sepolia to Your Wallet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.weatherxm.com/wallet/how-to-join-arbitrum-and-see-your-tokens"&gt;Joining Arbitrum and Viewing Tokens&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Polygon Amoy
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Network name:&lt;/strong&gt; Polygon Amoy Testnet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New RPC URL:&lt;/strong&gt; &lt;a href="https://rpc-amoy.polygon.technology/"&gt;https://rpc-amoy.polygon.technology/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chain ID:&lt;/strong&gt; 80002&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Currency symbol:&lt;/strong&gt; MATIC&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block explorer URL (Optional):&lt;/strong&gt; &lt;a href="https://www.oklink.com/amoy"&gt;https://www.oklink.com/amoy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faucet:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.alchemy.com/faucets/polygon-amoy"&gt;https://www.alchemy.com/faucets/polygon-amoy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://faucet.polygon.technology/"&gt;https://faucet.polygon.technology/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://polygon.technology/blog/introducing-the-amoy-testnet-for-polygon-pos"&gt;Read More: Introducing the Amoy Testnet for Polygon PoS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  BNB Chain Testnet
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Network name:&lt;/strong&gt; BNB Chain Testnet&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New RPC URL:&lt;/strong&gt; &lt;a href="https://data-seed-prebsc-1-s1.bnbchain.org:8545"&gt;https://data-seed-prebsc-1-s1.bnbchain.org:8545&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chain ID:&lt;/strong&gt; 97&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Currency symbol:&lt;/strong&gt; tBNB&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block explorer URL (Optional):&lt;/strong&gt; &lt;a href="https://testnet.bscscan.com"&gt;https://testnet.bscscan.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Useful Links:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://revoke.cash/learn/wallets/add-network/bnb-chain-testnet"&gt;Adding BNB Chain Testnet to Your Wallet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.bnbchain.org/en/testnet-faucet"&gt;BNB Chain Testnet Faucet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This list serves as a personal note of frequently used blockchain networks, shared for anyone in need. While it may not be exhaustive, it aims to provide convenient access to essential information. Your understanding is appreciated! 😄&lt;/p&gt;

</description>
    </item>
    <item>
      <title>NVM tips and tricks</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Tue, 06 Feb 2024 09:40:10 +0000</pubDate>
      <link>https://dev.to/particle4dev/nvm-tips-and-tricks-2p4j</link>
      <guid>https://dev.to/particle4dev/nvm-tips-and-tricks-2p4j</guid>
      <description>&lt;h2&gt;
  
  
  1. How to uninstall nvm?
&lt;/h2&gt;

&lt;p&gt;just remove directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rm -rf $NVM_DIR ~/.npm ~/.bower
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/nvm-sh/nvm/issues/298#issuecomment-30654686"&gt;https://github.com/nvm-sh/nvm/issues/298#issuecomment-30654686&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Install NVM with .nvm being installed in a different directory
&lt;/h2&gt;

&lt;p&gt;Simply set $NVM_DIR before running the install script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NVM_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;/workspace/.nvm &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; curl &lt;span class="nt"&gt;-o-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/nvm-sh/nvm/issues/1436"&gt;https://github.com/nvm-sh/nvm/issues/1436&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>nvm</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to connect to Mongo database using Mongo shell on Ubuntu?</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Mon, 29 Jan 2024 20:56:33 +0000</pubDate>
      <link>https://dev.to/particle4dev/how-to-connect-to-mongo-database-using-mongo-shell-2145</link>
      <guid>https://dev.to/particle4dev/how-to-connect-to-mongo-database-using-mongo-shell-2145</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;MongoDB, a widely used NoSQL database, provides developers with a flexible and scalable solution for managing large datasets. Connecting to a MongoDB database using the Mongo Shell is an essential skill for both developers and administrators. In this article, we will guide you through the step-by-step process of connecting to a MongoDB database using the Mongo Shell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To utilize the MongoDB Shell, you need a MongoDB deployment to connect to.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For a free cloud-hosted deployment, consider using &lt;a href="https://www.mongodb.com/cloud/atlas"&gt;MongoDB Atlas&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;If you want to run a local MongoDB deployment, refer to the &lt;a href="https://www.mongodb.com/docs/manual/installation/"&gt;Install MongoDB&lt;/a&gt; documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Supported MongoDB Versions:&lt;/strong&gt;&lt;br&gt;
You can use the MongoDB Shell to connect to MongoDB version 4.2 or greater.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: The following instructions are for Ubuntu 22.04 (Jammy).
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install gnupg and its required libraries:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;gnupg
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Retry importing the key:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-qO-&lt;/span&gt; https://www.mongodb.org/static/pgp/server-7.0.asc | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/trusted.gpg.d/server-7.0.asc
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Create the &lt;code&gt;/etc/apt/sources.list.d/mongodb-org-7.0.list&lt;/code&gt; file for Ubuntu 22.04 (Jammy):&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/mongodb-org-7.0.list
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Reload the local package database:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Install the &lt;code&gt;mongosh&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; mongodb-mongosh
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Confirm that &lt;code&gt;mongosh&lt;/code&gt; installed successfully:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;mongosh &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 2: Connect to MongoDB Atlas with mongosh
&lt;/h2&gt;

&lt;p&gt;To establish your connection, run the &lt;code&gt;mongosh&lt;/code&gt; command with your connection string and options:&lt;/p&gt;

&lt;p&gt;The connection string includes the following elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your cluster name&lt;/li&gt;
&lt;li&gt;A hash&lt;/li&gt;
&lt;li&gt;A flag for the API version&lt;/li&gt;
&lt;li&gt;A flag for the username you want to use to connect&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It resembles the following string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mongosh &lt;span class="s2"&gt;"mongodb+srv://YOUR_CLUSTER_NAME.YOUR_HASH.mongodb.net/"&lt;/span&gt; &lt;span class="nt"&gt;--apiVersion&lt;/span&gt; YOUR_API_VERSION &lt;span class="nt"&gt;--username&lt;/span&gt; YOUR_USERNAME

&lt;span class="c"&gt;# for example&lt;/span&gt;
mongosh &lt;span class="s2"&gt;"mongodb+srv://db.fakeuri.mongodb.net/"&lt;/span&gt; &lt;span class="nt"&gt;--apiVersion&lt;/span&gt; 1 &lt;span class="nt"&gt;--username&lt;/span&gt; admin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Run Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Switch Databases
&lt;/h3&gt;

&lt;p&gt;To display the current database, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This operation should return &lt;code&gt;test&lt;/code&gt;, which is the default database. To switch databases, use the &lt;code&gt;use &amp;lt;db&amp;gt;&lt;/code&gt; helper, as shown in the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;use &amp;lt;database&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a New Database and Collection
&lt;/h3&gt;

&lt;p&gt;To create a new database, use the &lt;code&gt;use &amp;lt;db&amp;gt;&lt;/code&gt; command with the desired database name. For instance, the following commands create the &lt;code&gt;myNewDatabase&lt;/code&gt; database and the &lt;code&gt;myCollection&lt;/code&gt; collection using the &lt;code&gt;insertOne()&lt;/code&gt; operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;use myNewDatabase
db.myCollection.insertOne&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; x: 1 &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the collection does not exist, MongoDB creates it when you first store data for that collection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Terminate a Running Command
&lt;/h3&gt;

&lt;p&gt;To terminate a running command or query in mongosh, press &lt;code&gt;Ctrl + C&lt;/code&gt;. When you enter &lt;code&gt;Ctrl + C&lt;/code&gt;, mongosh:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interrupts the active command.&lt;/li&gt;
&lt;li&gt;Tries to terminate the ongoing, server-side operation.&lt;/li&gt;
&lt;li&gt;Returns a command prompt.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If mongosh cannot cleanly terminate the running process, it issues a warning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Connecting to a MongoDB database using the Mongo Shell is a straightforward process that involves a few simple steps. Whether you're a developer building applications or an administrator managing databases, mastering the basics of the Mongo Shell is crucial for efficient MongoDB usage. Now that you've learned the essentials, you can explore further commands and functionalities to harness the full power of MongoDB for your projects.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>terminal</category>
      <category>ubuntu</category>
      <category>mongodbcrashcourse</category>
    </item>
    <item>
      <title>The lessons I learned after having a micro launch of my product on Reddit</title>
      <dc:creator>Nam Hoang</dc:creator>
      <pubDate>Fri, 26 Jan 2024 11:22:44 +0000</pubDate>
      <link>https://dev.to/particle4dev/the-lessons-i-learned-after-having-a-micro-launch-of-my-product-on-reddit-5ek0</link>
      <guid>https://dev.to/particle4dev/the-lessons-i-learned-after-having-a-micro-launch-of-my-product-on-reddit-5ek0</guid>
      <description>&lt;p&gt;First, I'd like to introduce &lt;a href="https://www.play-2048.com"&gt;my product&lt;/a&gt; a bit. My product is a &lt;a href="https://www.play-2048.com"&gt;2048 game&lt;/a&gt; website. I chose &lt;a href="(https://www.play-2048.com)"&gt;2048 game&lt;/a&gt; as the game because I was quite addicted to it when it was first released in 2014. In my opinion, it's a simple game but challenging to master. I also have quite a few ideas for it. Seeing successful websites like &lt;a href="http://online-solitaire.com"&gt;online-solitaire.com&lt;/a&gt; only strengthens my belief in my principle: Doing something as simple but achieving it to perfection will lead you to success!&lt;/p&gt;

&lt;p&gt;I create a &lt;a href="https://www.play-2048.com"&gt;website&lt;/a&gt; using my familiar technical stack: Next.js and Netlify. I spent about 20 hours building the initial version that could run, but I was not satisfied with the performance and the codebase. I thought it was very difficult to be extended. I then spent another 20 hours to rewrite the codebase and fix some performance issues.&lt;/p&gt;

&lt;p&gt;Finally, there was no plan beforehand. I just wanted to post it on a few subreddits and see people's reactions. Surprisingly, the majority of the responses were positive, and some were just about bugs and suggestions for new features. Here are the things I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Focus on one feature and do it well. Let the users feel comfortable using it. I have quite a few features I want to add, like a leaderboard and some other game variations. But that's for the future.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't be afraid to do things no one else wants to do. When I started, I thought no one would want another &lt;a href="https://www.play-2048.com"&gt;2048 game&lt;/a&gt; website. But here we are.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's all for today's sharing! Please follow the page! I will update the project's progress here ^^&lt;/p&gt;

&lt;p&gt;Origin: &lt;a href="https://www.namvhoang.com/blogs/2023-11-21-lessons-learned-micro-launch-product-reddit/"&gt;https://www.namvhoang.com/blogs/2023-11-21-lessons-learned-micro-launch-product-reddit/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>indiehackers</category>
      <category>sideprojects</category>
      <category>startup</category>
      <category>passiveincome</category>
    </item>
  </channel>
</rss>
