微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux系统中seq命令的用法

1、简单用法,直接加数字

[root@linuxprobe test]# seq 10  ## 输出1到10列表
1
2
3
4
5
6
7
8
9
10

 

2、设置起点、终点

[root@linuxprobe test]# seq 5 10  ##设置起点为5,终点为10,认的步长为1。
5
6
7
8
9
10

 

3、设置步长 

[root@linuxprobe test]# seq 1 2 10  ##步长为2
1
3
5
7
9
[root@linuxprobe test]# seq 1 3 10 ##步长为3
1
4
7
10

 

4、-w 设置输出数字同宽

[root@linuxprobe test]# seq 10
1
2
3
4
5
6
7
8
9
10
[root@linuxprobe test]# seq -w 10 ##设置同宽
01
02
03
04
05
06
07
08
09
10
[root@linuxprobe test]# seq -w 100 | tail  ##同上
091
092
093
094
095
096
097
098
099
100

 

5、指定数字宽度

[root@linuxprobe test]# seq -f %2g 10 ##指定宽度为2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[root@linuxprobe test]# seq -f %3g 10 ## 指定宽度为3
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

 

 

 

6、用0填充多余间隔

[root@linuxprobe test]# seq -f %02g 10
01
02
03
04
05
06
07
08
09
10
[root@linuxprobe test]# seq -f %03g 10
001
002
003
004
005
006
007
008
009
010

 

7、添加指定字符

[root@linuxprobe test]# seq -f xxx%02g 10
xxx01
xxx02
xxx03
xxx04
xxx05
xxx06
xxx07
xxx08
xxx09
xxx10
[root@linuxprobe test]# seq -f xxx%02gyyy 10
xxx01yyy
xxx02yyy
xxx03yyy
xxx04yyy
xxx05yyy
xxx06yyy
xxx07yyy
xxx08yyy
xxx09yyy
xxx10yyy

 

8、-s 选项用于指定输出分割符

[root@linuxprobe test]# seq -s " " 6 ## 以空格为分隔符
1 2 3 4 5 6
[root@linuxprobe test]# seq -s "--" 6 ## 以--为分隔符
1--2--3--4--5--6
[root@linuxprobe test]# seq -s ":" 6  ## 以:为分隔符
1:2:3:4:5:6

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。