天天看點

Seq指令的用法(shell)seq 1 10!/bin/bashseq -f"%3g" 9 11sed -f"%03g" 9 11 這樣的話數字位數不足部分是0

seq指令的用法

用于産生從某個數到另外一個數之間的所有整數

例一:

結果是1 2 3 4 5 6 7 8 9 10

例二:

for i in <code>seq 1 10</code>;

do

echo $i;

done

或者用

for i in $(seq 1 10)

也可以seq

-f, --format=format use printf style floating-point format (default: %g)

-s, --separator=string use string to separate numbers (default: n)

-w, --equal-width equalize width by padding with leading zeroes-f 選項 指定格式

9

10

11

% 後面指定數字的位數 預設是"%g",

"%3g"那麼數字位數不足部分是空格

% 前面制定字元串

seq -f "str%03g" 9 11

str009

str010

str011-w 指定輸出數字同寬 不能和-f一起用

seq -w -f"str%03g" 9 11

seq: format string may not be specified when printing equal width strings

seq -w 98 101

098

099

100

101

輸出是同寬的-s 指定分隔符 預設是回車

seq -s" " -f"str%03g" 9 11

str009 str010 str011

要指定t 做為分隔符号

seq -s"<code>echo -e "\t"</code>" 9 11指定nn作為分隔符号

seq -s"<code>echo -e "\n\n"</code>" 9 11

19293949596979899910911

得到的是個錯誤結果

不過一般也沒有這個必要 它預設的就是回車作為分隔符

幾個例子

awk 'begin { while (num &lt; 10 ) printf "dir%03dn", ++num ; exit}' | xargs mkdir

mkdir $(seq -f 'dir%03g' 1 10)

for i in <code>seq -f '%02g' 1 20</code>

if ! wget -p $home/tmp -c http://www.xxxsite.com/photo/$i.jpg ; then

wget -p $home/tmp -c $_

fi