如何在Linux中使用seq命令

发布时间:2021-03-20 17:05:07 作者:Leah
来源:亿速云 阅读:115

本篇文章给大家分享的是有关如何在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 
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,然后再指定成分隔符

以上就是如何在Linux中使用seq命令,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

推荐阅读:
  1. 如如何使用journalctl命令?
  2. linux的seq命令

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux seq命令

上一篇:如何在Linux中使用nl命令

下一篇:php中与html标签相关的函数有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》