欢迎来到代码驿站!

Linux

当前位置:首页 > 服务器 > Linux

Linux seq命令的使用详解

时间:2021-01-07 11:36:45|栏目:Linux|点击:

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 
1
2
3
4
5
[deng@localhost ~]$ 

4.2 输出1-5

[deng@localhost ~]$ seq 1 5
1
2
3
4
5
[deng@localhost ~]$ 

4.3 输出3-5

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

4.4 输出1 4 7 10

[deng@localhost ~]$ seq 1 3 10
1
4
7
10
[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 11
009
010
011
[deng@localhost ~]$ 

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

4.7 指定格式输出

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

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

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

[deng@localhost ~]$ seq -w 9 11
09
10
11
[deng@localhost ~]$ 
 

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

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

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

4.10 使用tab键分隔数字

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

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

05. 附录

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

上一篇:Linux服务器编程之utime()函数修改文件存取时间

栏    目:Linux

下一篇:如何在linux系统的host上安装windows系统的guest

本文标题:Linux seq命令的使用详解

本文地址:http://www.codeinn.net/misctech/42018.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有