Linux中seq命令的用法

來源:互聯網
上載者:User
用於產生從某個數到另外一個數之間的所有整數
  例一:
  # seq 1 10
  結果是1 2 3 4 5 6 7 8 9 10
  例二:
  #!/bin/bash
  for i in `seq 1 10`;
  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 選項   指定格式
#seq -f"%3g" 9 11
9
10
11
% 後面指定數位位元 預設是"%g",
"%3g"那麼數字位元不足部分是空格
#sed -f"%03g" 9 11 這樣的話數字位元不足部分是0
% 前面制定字串
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"`echo -e "/t"`" 9 11

 

指定/n/n作為分隔字元號
seq -s"`echo -e "/n/n"`" 9 11
19293949596979899910911
得到的是個錯誤結果
不過一般也沒有這個必要 它預設的就是斷行符號作為分隔字元

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.