snipt

Ctrl+h for KB shortcuts

Bash

AWK timestamp each line

<cmd> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'
https://snipt.net/embed/3c95a0173f04f01070d3df97f8aa825b/
https://snipt.net/raw/3c95a0173f04f01070d3df97f8aa825b/
3c95a0173f04f01070d3df97f8aa825b
bash
Bash
1
2016-09-27T21:56:36
True
False
False
Mar 25, 2016 at 06:05 PM
/api/public/snipt/144950/
awk-timestamp-each-line
<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 id="L-1"><a name="L-1"></a>&lt;cmd&gt; <span class="p">|</span> awk <span class="s1">&#39;{ print strftime(&quot;%Y-%m-%d %H:%M:%S&quot;), $0; fflush(); }&#39;</span> </span></pre></div> </td></tr></table>
awk, bash, console, timestamp

Bash

validate IP

[[ "$IP" =~ ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]] && echo "valid" || echo "invalid"
https://snipt.net/embed/a9253d8df5f51a88c9becb1b4c407589/
https://snipt.net/raw/a9253d8df5f51a88c9becb1b4c407589/
a9253d8df5f51a88c9becb1b4c407589
bash
Bash
1
2016-09-27T21:56:37
True
False
False
Oct 18, 2015 at 12:39 PM
/api/public/snipt/141789/
validate-ip
<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 id="L-1"><a name="L-1"></a><span class="o">[[</span> <span class="s2">&quot;</span><span class="nv">$IP</span><span class="s2">&quot;</span> <span class="o">=</span>~ ^<span class="o">(([</span>0-9<span class="o">]</span><span class="p">|</span><span class="o">[</span>1-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>1<span class="o">[</span>0-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>2<span class="o">[</span>0-4<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>25<span class="o">[</span>0-5<span class="o">])</span>.<span class="o">){</span>3<span class="o">}([</span>0-9<span class="o">]</span><span class="p">|</span><span class="o">[</span>1-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>1<span class="o">[</span>0-9<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>2<span class="o">[</span>0-4<span class="o">][</span>0-9<span class="o">]</span><span class="p">|</span>25<span class="o">[</span>0-5<span class="o">])</span><span class="nv">$ </span><span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nb">echo</span> <span class="s2">&quot;valid&quot;</span> <span class="o">||</span> <span class="nb">echo</span> <span class="s2">&quot;invalid&quot;</span> </span></pre></div> </td></tr></table>
bash, ip, linux

Text only

Find directory

find . -type d -name "dir name"
https://snipt.net/embed/4bf1c8134a2ba8424e21dd1b156fac6a/
https://snipt.net/raw/4bf1c8134a2ba8424e21dd1b156fac6a/
4bf1c8134a2ba8424e21dd1b156fac6a
text
Text only
1
2016-09-27T21:56:38
True
False
False
Oct 14, 2015 at 05:13 AM
/api/public/snipt/141676/
find-directory-ea4b954d
<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 id="L-1"><a name="L-1"></a>find . -type d -name &quot;dir name&quot; </span></pre></div> </td></tr></table>
bash, directory, find

Bash

sed append to match

1
2
3
4
file="/path/to/file"
regex="find this .*"
suffix="-suffix"
sed -i "s/$regex/&$suffix/" $file
https://snipt.net/embed/940f084dd40897180b5a15ed7a27be6c/
https://snipt.net/raw/940f084dd40897180b5a15ed7a27be6c/
940f084dd40897180b5a15ed7a27be6c
bash
Bash
4
2016-09-27T21:56:38
True
False
False
Oct 13, 2015 at 06:33 AM
/api/public/snipt/141656/
sed-append-to-match
<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> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="nv">file</span><span class="o">=</span><span class="s2">&quot;/path/to/file&quot;</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">regex</span><span class="o">=</span><span class="s2">&quot;find this .*&quot;</span> </span><span id="L-3"><a name="L-3"></a><span class="nv">suffix</span><span class="o">=</span><span class="s2">&quot;-suffix&quot;</span> </span><span id="L-4"><a name="L-4"></a>sed -i <span class="s2">&quot;s/</span><span class="nv">$regex</span><span class="s2">/&amp;</span><span class="nv">$suffix</span><span class="s2">/&quot;</span> <span class="nv">$file</span> </span></pre></div> </td></tr></table>
append, bash, linux, regex, sed

Bash

zip with find

find . -type f  -print  | zip k.zip -@
https://snipt.net/embed/42503fad33e519f0f8490094329a77d2/
https://snipt.net/raw/42503fad33e519f0f8490094329a77d2/
42503fad33e519f0f8490094329a77d2
bash
Bash
1
2016-09-27T21:56:38
True
False
False
Oct 08, 2015 at 08:20 AM
/api/public/snipt/141578/
zip-with-find
<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 id="L-1"><a name="L-1"></a>find . -type f -print <span class="p">|</span> zip k.zip -@ </span></pre></div> </td></tr></table>
"find. linux", bash, zip
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.