<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Shell on Foam 的博客</title>
    <link>https://blog.foamzou.com/tags/shell/</link>
    <description>Recent content in Shell on Foam 的博客</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    <lastBuildDate>Mon, 20 Dec 2021 14:13:36 +0800</lastBuildDate>
    <atom:link href="https://blog.foamzou.com/tags/shell/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>实用 shell</title>
      <link>https://blog.foamzou.com/posts/shell-skill/</link>
      <pubDate>Mon, 20 Dec 2021 14:13:36 +0800</pubDate>
      <guid>https://blog.foamzou.com/posts/shell-skill/</guid>
      <description>&lt;h2 id=&#34;文本处理&#34;&gt;文本处理&lt;/h2&gt;
&lt;h3 id=&#34;清除每行头尾部的空白符&#34;&gt;清除每行头&amp;amp;尾部的空白符&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;awk &amp;#39;{$1=$1;print}&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ref: &lt;a href=&#34;https://stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file&#34;&gt;https://stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;在一个文本随机选取若干行&#34;&gt;在一个文本随机选取若干行&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;// macos 则先 brew install coreutils，然后用 gshuf
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;shuf foo.txt | head -n 100
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;cat foo.txt | awk &amp;#39;BEGIN{srand();}{print rand()&amp;#34;\t&amp;#34;$0}&amp;#39; | sort -k1 -n | cut -f2- | head -n 100
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ref: &lt;a href=&#34;https://stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file&#34;&gt;https://stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;截取每行的前几个字符&#34;&gt;截取每行的前几个字符&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;cut -c 1-3 file // 前三个字符
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;ref: &lt;a href=&#34;https://stackoverflow.com/questions/19869511/how-to-restrict-length-of-string-present-in-a-line-using-linux&#34;&gt;https://stackoverflow.com/questions/19869511/how-to-restrict-length-of-string-present-in-a-line-using-linux&lt;/a&gt;&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
