snipt

Ctrl+h for KB shortcuts

Bash

Remove duplicate lines without sorting file

1
2
3
# To remove duplicate lines from a text file without messing up the lines' order (that means, without using "sort" and "uniq"), run the following:

awk ' !x[$0]++' FILE
https://snipt.net/embed/3e41dbd990a3fc077f84b082283361b9/
/raw/3e41dbd990a3fc077f84b082283361b9/
3e41dbd990a3fc077f84b082283361b9
bash
Bash
3
2019-07-20T11:13:50
True
False
False
/api/public/snipt/18249/
remove-duplicate-lines-without-sorting-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># To remove duplicate lines from a text file without messing up the lines&#39; order (that means, without using &quot;sort&quot; and &quot;uniq&quot;), run the following:</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>awk <span class="s1">&#39; !x[$0]++&#39;</span> FILE </span></pre></div> </td></tr></table>
awk, bash, sort, uniq

Bash

number of file open by command

lsof | awk '{printf("%s\n",$1)}' | sort | uniq -c | sort -n
https://snipt.net/embed/75ca64e0793a44cbe1d4ec8120e4a6d7/
/raw/75ca64e0793a44cbe1d4ec8120e4a6d7/
75ca64e0793a44cbe1d4ec8120e4a6d7
bash
Bash
2
2019-07-22T12:04:11
True
False
False
/api/public/snipt/12772/
number-of-file-open-by-command
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>lsof <span class="p">|</span> awk <span class="s1">&#39;{printf(&quot;%s\n&quot;,$1)}&#39;</span> <span class="p">|</span> sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -n </span></pre></div> </td></tr></table>
awk, bash, files, lsof, sh, sort, uniq

Bash

Show most frequently used commands

history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail
https://snipt.net/embed/c6a0aef521756f73c3adb1b053ee92a4/
/raw/c6a0aef521756f73c3adb1b053ee92a4/
c6a0aef521756f73c3adb1b053ee92a4
bash
Bash
1
2019-07-07T15:56:19
True
False
False
/api/public/snipt/5011/
show-most-frequently-used-commands
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nb">history</span> <span class="p">|</span> awk <span class="s1">&#39;{print $2}&#39;</span> <span class="p">|</span> awk <span class="s1">&#39;BEGIN {FS=&quot;|&quot;}{print $1}&#39;</span> <span class="p">|</span> sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -n <span class="p">|</span> tail </span></pre></div> </td></tr></table>
awk, bash, history, sort, tail, uniq