Linux seq命令的使用详解


01. 命令概述

seq命令用于产生整数序列。

02. 命令格式

用法:

 seq [选项]... 尾数 seq [选项]... 首数 尾数 seq [选项]... 首数 增量 尾数

03. 常用选项

以指定增量从首数开始打印数字到尾数。

-f, –format=格式 使用printf 样式的浮点格式
-s, –separator=字符串 使用指定字符串分隔数字(默认使用:\n)
-w, –equal-width 在列前添加0 使得宽度相同
–help 显示此帮助信息并退出
–version 显示版本信息并退出

04. 参考示例

4.1 输出1-5

[deng@localhost ~]$ seq 5 12345[deng@localhost ~]$ 

4.2 输出1-5

[deng@localhost ~]$ seq 1 512345[deng@localhost ~]$ 

4.3 输出3-5

[deng@localhost ~]$ seq 3 5 345[deng@localhost ~]$ 

4.4 输出1 4 7 10

[deng@localhost ~]$ seq 1 3 1014710[deng@localhost ~]$ 

4.5 指定格式输出

[deng@localhost ~]$ seq -f "%3g" 9 11 9 10 11[deng@localhost ~]$ 

意思是-f指定格式,%后面指定3位数,默认是%g,%3g不够位数的地方都是空格填补

4.6 指定格式输出

[deng@localhost ~]$ seq -f "%03g" 9 11009010011[deng@localhost ~]$ 

意思是打印三位,不足的地方用0填补

4.7 指定格式输出

[deng@localhost ~]$ seq -f "str%03g" 9 11str009str010str011[deng@localhost ~]$ 

意思是打印三位不足的地方以0填补,在前面加上str

4.8 在列前添加0使得宽度相同

[deng@localhost ~]$ seq -w 9 11091011[deng@localhost ~]$  

当输出等宽字符串时不应再指定格式字符串,-w与-f不能一起用

4.9 使用指定字符串分隔数字

[deng@localhost ~]$ seq -s " " -f "str%03g" 9 11str009 str010 str011[deng@localhost ~]$  

4.10 使用tab键分隔数字

[deng@localhost ~]$ seq -s "`echo -e '\t'`" 9 119    10   11[deng@localhost ~]$  

先用命令做成一个tab,然后再指定成分隔符

05. 附录

参考: 【Linux】一步一步学Linux系列教程汇总

本篇文章到此结束,如果您有相关技术方面疑问可以联系我们技术人员远程解决,感谢大家支持本站!