2019-04-21 11:50:48 +08:00

43 lines
2.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="seq">seq</h1>
<p>以指定增量从首数开始打印数字到尾数</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>seq命令</strong> 用于产生从某个数到另外一个数之间的所有整数。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">seq [选项]... 尾数
seq [选项]... 首数 尾数
seq [选项]... 首数 增量 尾数</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-f, --format=格式 使用printf 样式的浮点格式
-s, --separator=字符串 使用指定字符串分隔数字(默认使用:\n
-w, --equal-width 在列前添加0 使得宽度相同</code></pre>
<h3 id="实例">实例</h3>
<p><strong>-f选项指定格式</strong></p>
<pre><code class="language-bash">#seq -f&quot;%3g&quot; 9 11
9
10
11</code></pre>
<p><code>%</code>后面指定数字的位数 默认是<code>%g</code><code>%3g</code>那么数字位数不足部分是空格。</p>
<pre><code class="language-bash">#sed -f&quot;%03g&quot; 9 11
#seq -f&quot;str%03g&quot; 9 11
str009
str010
str011</code></pre>
<p>这样的话数字位数不足部分是0<code>%</code>前面制定字符串。</p>
<p><strong>-w选项指定输出数字同宽</strong></p>
<pre><code class="language-bash">seq -w 98 101
098
099
100
101</code></pre>
<p>不能和<code>-f</code>一起用,输出是同宽的。</p>
<p><strong>-s选项指定分隔符默认是回车</strong></p>
<pre><code class="language-bash">seq -s&quot; &quot; -f&quot;str%03g&quot; 9 11
str009 str010 str011</code></pre>
<p>要指定<code>/t</code>做为分隔符号:</p>
<pre><code class="language-bash">seq -s&quot;`echo -e &quot;/t&quot;`&quot; 9 11</code></pre>
<p>指定<code>\n</code>作为分隔符号:</p>
<pre><code class="language-bash">seq -s&quot;`echo -e &quot;\n&quot;`&quot; 9 11
19293949596979899910911</code></pre>
<p>得到的是个错误结果,不过一般也没有这个必要,它默认的就是回车作为分隔符。</p>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->