1. 程式人生 > 實用技巧 >linux系統中seq命令的用法

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