【Linux】一步一步学Linux——seq命令(221)

00. 目录

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系列教程汇总

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值