seq

作者: 不排版 | 来源:发表于2018-03-29 17:41 被阅读6次

seq命令用于产生从某个数到另外一个数之间的所有整数。

语法

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">seq [选项]... 尾数
seq [选项]... 首数 尾数
seq [选项]... 首数 增量 尾数</pre>

选项

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">-f, --format=格式 使用printf 样式的浮点格式
-s, --separator=字符串 使用指定字符串分隔数字(默认使用:\n)
-w, --equal-width 在列前添加0 使得宽度相同</pre>

实例

-f选项:指定格式

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#seq -f"%3g" 9 11
9
10
11</pre>

%后面指定数字的位数 默认是%g%3g那么数字位数不足部分是空格。

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">#sed -f"%03g" 9 11

seq -f"str%03g" 9 11

str009
str010
str011</pre>

这样的话数字位数不足部分是0,%前面制定字符串。

-w选项:指定输出数字同宽

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">seq -w 98 101
098
099
100
101</pre>

不能和-f一起用,输出是同宽的。

-s选项:指定分隔符(默认是回车)

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">seq -s" " -f"str%03g" 9 11
str009 str010 str011</pre>

要指定/t做为分隔符号:

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">seq -s"[echo](http://man.linuxde.net/echo "echo命令") -e "/t"" 9 11</pre>

指定\n作为分隔符号:

<pre style="margin: 0px 0px 25px; background: rgb(230, 233, 237); border-left: 4px solid rgb(122, 208, 58); color: rgb(34, 34, 34); font-style: normal; font-variant: normal; font-weight: 400; font-stretch: normal; font-size: 12px; line-height: 20px; font-family: Consolas, "Courier New", Courier, monospace; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; overflow: hidden; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">seq -s"echo -e "\n"" 9 11
19293949596979899910911</pre>

得到的是个错误结果,不过一般也没有这个必要,它默认的就是回车作为分隔符。

相关文章

网友评论

      本文标题:seq

      本文链接:https://www.haomeiwen.com/subject/jvcvcftx.html