linux命令之seq
生活随笔
收集整理的這篇文章主要介紹了
linux命令之seq
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
seq命令簡述
seq命令比較常用,在需要做循環的時候用于產生一個序列是再合適不過的工具了,常用方法也比較簡單: Usage: seq [OPTION]... LAST seq [OPTION]... FIRST LAST seq [OPTION]... FIRST INCREMENT LAST Print numbers from FIRST to LAST, in steps of INCREMENT. # 以INCREMENT為步長打印從FIRST到LAST的數字 其參數也比較簡單,主要有以下幾個: # 指定格式 -f, --format=FORMAT? ? ? use printf style floating-point FORMAT # 指定分隔符 -s, --separator=STRING? ?use STRING to separate numbers (default: \n) # 等寬參數,在日常工作中非常有用。 -w, --equal-width? ? ? ? equalize width by padding with leading zeroes基本用法
默認的分隔符為換行(\n) thatsit:~ # seq 1 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 thatsit:~ #?
# 指定分隔符為空格 thatsit:~ # seq -s " " 1 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 thatsit:~ ## 使用等寬參數
thatsit:~ # seq -w -s " " 1 20 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 thatsit:~ #高級用法
高級用法主要在于-f參數的使用上,具體使用幫助可以通過info seq來獲取。 可以通過printf指定format來輸出兩位精度的浮點數、十進制(默認)、十六進制、八進制等的序列: 下面以seq 1 20為例進行示范(printf中用一個空格來分隔數據):? 十進制(默認): thatsit:~ # printf '%g ' `seq 1 20` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 thatsit:~ #八進制:
thatsit:~ # printf '%o ' `seq 1 20` 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 thatsit:~ #十六進制:
thatsit:~ # printf '%x ' `seq 1 20` 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 thatsit:~ #兩位數精度的浮點數:
thatsit:~ # printf '%.2f ' `seq 1 20` 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 thatsit:~ #四位數精度的浮點數:
thatsit:~ # printf '%.4f ' `seq 1 20` 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 thatsit:~ #others
此外還有一些科學計數法等格式,一般用不到,了解下即可:
如:%e、%E、a%、A%等轉載于:https://www.cnblogs.com/thatsit/p/5523198.html
總結
以上是生活随笔為你收集整理的linux命令之seq的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JBOSS内存溢出处理
- 下一篇: gcc代码反汇编查看内存分布[2]: a