seq

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 1 10 结果是1 2 3 4 5 6 7 ...
    飞奔的大虎阅读 8,272评论 0 1
  • .bat脚本基本命令语法 目录 批处理的常见命令(未列举的命令还比较多,请查阅帮助信息) 1、REM 和 :: 2...
    庆庆庆庆庆阅读 12,549评论 1 19
  • 用于产生从某个数到另外一个数之间的所有整数 例一: # seq 1 10 结果是1 2 3 4 5 6 7 8 9...
    Ten_Minutes阅读 10,733评论 0 1
  • 个人学习批处理的初衷来源于实际工作;在某个迭代版本有个BS(安卓手游模拟器)大需求,从而在测试过程中就重复涉及到...
    Luckykailiu阅读 10,214评论 0 11
  • 我蹩脚的文字实在难以面对观众,但每天和自己的心灵对话已经成了习惯。 元月2号的清晨,无意间看见朋友发在微信上...
    心际流尘阅读 1,553评论 0 0